首先引入相关pom

        <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.0.1</version>
</dependency> <dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>2.1.5</version>
</dependency> <dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.16</version>
</dependency> <dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.16</version>
</dependency>

新建MyMapper类

package com.chao.notify.mapper.base;

import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.common.MySqlMapper; public interface MyMapper<T> extends Mapper<T>, MySqlMapper<T> { }

新建UUIdGenId 用于uuid主键

public class UUIdGenId implements GenId<String> {
@Override
public String genId(String s, String s1) {
return UUID.randomUUID().toString().replace("-","");
}
}

新建model类

@Table(name = "t_user")
public class TUser { @Id
@KeySql(genId = UUIdGenId.class)
private String id; @Column(unique = true)
private String username; private String password; private String salt; private String name;
/**
* 0 未知
* 1 男
* 2 女
*/
private Integer sex; private String phone; private String address; private String notes; /**
* 停用状态
* true 停用
* false 启用
*/
private Boolean disabled; /**
* 用户角色
* admin 管理员
* public 普通用户
*/
private String role; /**
* 创建时间
*/
private Date at; /**
* 登录时间
*/
private Date loginAt; public String getId() {
return id;
} public void setId(String id) {
this.id = id;
} public String getUsername() {
return username;
} public void setUsername(String username) {
this.username = username;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} public String getSalt() {
return salt;
} public void setSalt(String salt) {
this.salt = salt;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public Integer getSex() {
return sex;
} public void setSex(Integer sex) {
this.sex = sex;
} public String getPhone() {
return phone;
} public void setPhone(String phone) {
this.phone = phone;
} public String getAddress() {
return address;
} public void setAddress(String address) {
this.address = address;
} public String getNotes() {
return notes;
} public void setNotes(String notes) {
this.notes = notes;
} public Boolean getDisabled() {
return disabled;
} public void setDisabled(Boolean disabled) {
this.disabled = disabled;
} public String getRole() {
return role;
} public void setRole(String role) {
this.role = role;
} public Date getAt() {
return at;
} public void setAt(Date at) {
this.at = at;
} public Date getLoginAt() {
return loginAt;
} public void setLoginAt(Date loginAt) {
this.loginAt = loginAt;
}
}

新建UserMapper类

@Mapper
public interface UserMapper extends MyMapper<TUser> { }

application.properties配置

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:/test?serverTimezone=Asia/Shanghai&useSSL=false
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource #初始化链接数 最小空闲链接数 最大链接数
spring.datasource.druid.initial-size=
spring.datasource.druid.min-idle=
spring.datasource.druid.max-active=
#获取连接的超时时间 单位毫秒
spring.datasource.druid.max-wait=
#配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
spring.datasource.druid.time-between-eviction-runs-millis= mybatis.type-aliases-package=com.chao.notify.model
mapper.mappers=com.chao.notify.mapper.base.MyMapper

springboot 使用 mybatis + mapper的更多相关文章

  1. SpringBoot 3.SpringBoot 整合 MyBatis 逆向工程以及 MyBatis 通用 Mapper

    一.添加所需依赖,当前完整的pom文件如下: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=&qu ...

  2. No MyBatis mapper was found in '[com.wuji.springboot]' package. Please check your configuration

    No MyBatis mapper was found in '[com.wuji.springboot]' package. Please check your configuration. 这个原 ...

  3. SpringBoot 集成Mybatis时 使用通用插件Mapper 注意事项

    1.如果在SpringBoot的启动入口类上面加入注解 @MapperScan(basePackages = "com.leecx.mapper")      使用的是   org ...

  4. springboot和mybatis集成,自动生成model、mapper,增加mybatis分页功能

    整体思路和http://www.cnblogs.com/mahuan2/p/5859921.html相同. 主要讲maven的pom.xml和一些配置变化,详细说明. 软件简介 Spring是一个流行 ...

  5. SpringBoot使用MyBatis报错:Error invoking SqlProvider method (tk.mybatis.mapper.provider.base.BaseInsertProvider.dynamicSQL)

    © 版权声明:本文为博主原创文章,转载请注明出处  1. 错误描述 使用SpringBoot集成MyBatis框架,并且使用 mapper-spring-boot-starter 自动生成MyBati ...

  6. springboot整合mybatis通用Mapper

    参考: https://blog.csdn.net/x18707731829/article/details/82814095 https://www.jianshu.com/p/6d2103451d ...

  7. SpringBoot 2.0 mybatis mapper通用类

    <!---mybatis通用类包含mybatis和连接池 mybatis和连接池就不需要引入--> <dependency> <groupId>tk.mybatis ...

  8. springboot中通用mapper结合mybatis generator的使用

    通用mapper就是指的是  tk.mybatis  包下的.这个是通用mapper就是说自动生成的dao层需要继承这个框架提供的mapper类.而我们之前用的org.mybatis这个最开始是普通的 ...

  9. springboot配置mybatis的mapper路径

    1.在src/main/resources/目录下新建mybatis文件夹,将xxx.xml文件放入该文件夹内 2.在application.yml文件中配置: mybatis: configurat ...

随机推荐

  1. FIS 雪碧图sprite合并

    1 安装fis(必须先安装node和npm):npm install -g fis3 2 构建项目发布到根目录下的output:fis3 release -d ./output 项目根目录:FIS3 ...

  2. BZOJ4009:[HNOI2015]接水果

    浅谈树状数组与线段树:https://www.cnblogs.com/AKMer/p/9946944.html 题目传送门:https://www.lydsy.com/JudgeOnline/prob ...

  3. Windows 7下Git SSH 创建Key的步骤

    1.首先你要安装Git工具 下载地址:https://git-scm.com/downloads 2.右键鼠标,选中 “Git Bash here”,当然你也可以在windows的 “开始”---&g ...

  4. mina中的发送延时

    由于项目需要,用到了 mina 框架进行 tcp 通讯.我是初次接触 mina,于是从 Hello world 开始学习了 mina .期间遇到了一个奇怪的发送数据的延迟问题,解决的过程是曲折的,但找 ...

  5. selenium如何获取已定位元素的属性值?

    HTML源代码: <div class="res-status" data-fortune="5" data-selfsos="" d ...

  6. 【转】ruby 时间日期处理

    我们可以使用Time类来生成一个当前时间的对象: t = Time.new 或 t = Time.now Time类有类方法mktime(同义方法是local方法)来根据传入的参数生成时间对象,并且它 ...

  7. 排序----demo----

    排序1---冒泡法: 单向冒泡排序的基本原理就是:对于给定的n个数据,从第一个数据开始一次对相邻的两个数据进行比较,当前面的数据大于后面的数据时,交换位置,进行一轮比较和换位后,n个数据中最大的那个被 ...

  8. stm32与三菱PLC通信

    一.三菱PLC通讯概要   三菱PLC FX系列通信结构如下图所示: 三菱PLC FX系列的通信规格如下图所示: 三菱PLC FX系列一般有以下几种通信模块,以FX2N为例: FX2N-232-BD ...

  9. jquery获取设置服务器控件的方法

    jquery获取设置服务器控件的方法 获取TextBox,HiddenField,Label的值.例如: <asp:TextBox ID="txtBoxID" runat=& ...

  10. linux压缩包安装jdk

    1.下载jdk压缩包 $ wget http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa00 ...