本文共 28315 字,大约阅读时间需要 94 分钟。
MyBatis-Plus(简称 MP)是一个 MyBatis 的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发、提高效率而生。
特性:
MyBatis-Plus 官网:
MyBatis-Plus 示例工程:
MyBatis 官网:
Spring Data JPA:
Active Record 模式-百度百科:
pom.xml
引入依赖 mybatis-plus、lombok、spring-bootspring-boot-starter-parent org.springframework.boot 2.1.3.RELEASE org.springframework.boot spring-boot-starter org.springframework.boot spring-boot-starter-test test org.projectlombok lombok true com.baomidou mybatis-plus-boot-starter 3.4.2 com.baomidou mybatis-plus 3.4.2 mysql mysql-connector-java junit junit 4.12 test
application.yml
# mysql 连接配置spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/mp-db?useSSL=false&characterEncoding=UTF-8&serverTimezone=GMT%2B8 username: root password: 123456# 输入日志,查看 sql 语句logging: level: root: warn org.example.dao: trace pattern: console: '%p%m%n'
App.java
启动 spring-bootpackage org.example;import org.mybatis.spring.annotation.MapperScan;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;/** * spring-boot 启动入口 * */@SpringBootApplication@MapperScan({ "org.example.dao"})public class App { public static void main( String[] args ) { SpringApplication.run(App.class, args); }}
#创建用户表CREATE TABLE user ( id BIGINT(20) PRIMARY KEY NOT NULL COMMENT '主键', name VARCHAR(30) DEFAULT NULL COMMENT '姓名', age INT(11) DEFAULT NULL COMMENT '年龄', email VARCHAR(50) DEFAULT NULL COMMENT '邮箱', manager_id BIGINT(20) DEFAULT NULL COMMENT '直属上级id', create_time DATETIME DEFAULT NULL COMMENT '创建时间', CONSTRAINT manager_fk FOREIGN KEY (manager_id) REFERENCES user (id)) ENGINE=INNODB CHARSET=UTF8;#初始化数据:INSERT INTO user (id, name, age, email, manager_id, create_time)VALUES (1087982257332887553, '大boss', 40, 'boss@baomidou.com', NULL , '2019-01-11 14:20:20'), (1088248166370832385, '王天风', 25, 'wtf@baomidou.com', 1087982257332887553 , '2019-02-05 11:12:22'), (1088250446457389058, '李艺伟', 28, 'lyw@baomidou.com', 1088248166370832385 , '2019-02-14 08:31:16'), (1094590409767661570, '张雨琪', 31, 'zjq@baomidou.com', 1088248166370832385 , '2019-01-14 09:15:15'), (1094592041087729666, '刘红雨', 32, 'lhm@baomidou.com', 1088248166370832385 , '2019-01-14 09:48:16');
entity/User.java
package org.example.entity;import lombok.Data;import java.time.LocalDateTime;/*** * 用户实体类 * */@Datapublic class User { // 员工 ID private Long id; // 姓名 private String name; // 年龄 private Integer age; // 邮箱 private String email; // 上级领导 ID private Long managerId; // 创建时间 private LocalDateTime createTime;}
dao/UserMapper.java
(接口)package org.example.dao;import com.baomidou.mybatisplus.core.mapper.BaseMapper;import org.example.entity.User;public interface UserMapper extends BaseMapper{ }
AppTest.java
package org.example;import org.example.dao.UserMapper;import org.example.entity.User;import org.junit.Assert;import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.boot.test.context.SpringBootTest;import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;import java.util.List;@RunWith(SpringJUnit4ClassRunner.class)@SpringBootTestpublic class AppTest { @Autowired private UserMapper userMapper; /** * 查询列表 * */ @Test public void select() { Listusers = userMapper.selectList(null); // 判断预期值与实际值是否相同 // Assert.assertEquals(5, users.size()); // 循环输出 users.forEach(System.err::println); }}
注解 | 说明 |
---|---|
@TableName(“数据库表名”) | 指定实体类对应的数据库表名 |
@TableId | 指定属性作为主键,mp 默认 id 为主键 |
@TableId(type = IdType.ASSIGN_UUID) | 指定属性作为主键,并指定主键策略 |
@TableField(“数据库表字段名”) | 指定属性对应的数据库表字段名 |
@TableField(exist=false) | 实体属性排除映射;将属性标记为非数据库表字段 |
@TableField(condition = SqlCondition.LIKE) | 当实体对象作为条件构造器的查询条件时,属性可进行 like 查询,而非默认的等值(SqlCondition 中还有其它常量可选) |
@Testpublic void selectById(){ // 根据 ID 进行查询 User user = userMapper.selectById(1087982257332887553L); System.err.println(user);}
@Testpublic void selectBatchIds(){ Listids = Arrays.asList(1087982257332887553L, 1088248166370832385L); // 根据 ID 列表进行查询 List users = userMapper.selectBatchIds(ids); users.forEach(System.err::println);}
@Testpublic void selectByMap(){ Map map = new HashMap(); map.put("name", "大boss"); // 数据库表字段名 map.put("age", 40); // sql:where name = '大boss' and age =40 // 根据 Map {name : value} 进行查询 Listusers = userMapper.selectByMap(map); users.forEach(System.err::println);}
where name like ‘%雨%’ and age < 40
@Testpublic void selectByWrapper(){ // 创建条件构造器 QueryWrapperqueryWrapper = Wrappers.query(); queryWrapper.like("name", "雨") .lt("age", 40); // 数据库表字段名 // 根据条件构造器进行查询 List users = userMapper.selectList(queryWrapper); users.forEach(System.err::println);}
where name like ‘%雨%’ and age between 20 and 40 and email is not null
@Testpublic void selectByWrapper2(){ // 创建条件构造器 QueryWrapperqueryWrapper = Wrappers.query(); queryWrapper.like("name", "雨") .between("age", 20, 40) .isNotNull("email"); // 数据库表字段名 // 根据条件构造器进行查询 List users = userMapper.selectList(queryWrapper); users.forEach(System.err::println);}
where name like ‘张%’ or age >= 30 order by age desc,id asc
@Testpublic void selectByWrapper3(){ // 创建条件构造器 QueryWrapperqueryWrapper = Wrappers.query(); queryWrapper.like("name", "张%") .or() .ge("age", 30) .orderByDesc("age") .orderByAsc("id"); // 数据库表字段名 // 根据条件构造器进行查询 List users = userMapper.selectList(queryWrapper); users.forEach(System.err::println);}
where date_format(create_time, ‘%Y-%m-%d’)
and manager_id in (select id from user where name like ‘王%’)
@Testpublic void selectByWrapper4(){ // 创建条件构造器 QueryWrapperqueryWrapper = Wrappers.query(); queryWrapper.apply("date_format(create_time, '%Y-%m-%d') = {0}" , "2019-02-14") // {0} 参数序号 .inSql("manager_id" , "select id from user where name like '王%'"); // 根据条件构造器进行查询 List users = userMapper.selectList(queryWrapper); users.forEach(System.err::println);}
where name like ‘王%’ and (age<40 or email is not null)
@Testpublic void selectByWrapper5(){ // 创建条件构造器 QueryWrapperqueryWrapper = Wrappers.query(); queryWrapper.likeRight("name", "王") .and( wq->wq.lt("age", 40) .or() .isNotNull("email") ); // 数据库表字段名 // 根据条件构造器进行查询 List users = userMapper.selectList(queryWrapper); users.forEach(System.err::println);}
where name like ‘王%’ or (age<40 and age>20 and email is not null)
@Testpublic void selectByWrapper6(){ // 创建条件构造器 QueryWrapperqueryWrapper = Wrappers.query(); queryWrapper.likeRight("name", "王") .or( wq->wq.lt("age", 40) .gt("age", 20) .isNotNull("email") ); // 数据库表字段名 // 根据条件构造器进行查询 List users = userMapper.selectList(queryWrapper); users.forEach(System.err::println);}
where (age<40 or email is not null) and name like ‘王%’
@Testpublic void selectByWrapper7(){ // 创建条件构造器 QueryWrapperqueryWrapper = Wrappers.query(); queryWrapper.nested( wq->wq.lt("age", 40).or().isNotNull("email") ) .likeRight("name", "王"); // 数据库表字段名 // 根据条件构造器进行查询 List users = userMapper.selectList(queryWrapper); users.forEach(System.err::println);}
where age in (30, 31, 34)
@Testpublic void selectByWrapper8(){ // 创建条件构造器 QueryWrapperqueryWrapper = Wrappers.query(); queryWrapper.in("age", Arrays.asList(30, 31, 32)); // 数据库表字段名 // 根据条件构造器进行查询 List users = userMapper.selectList(queryWrapper); users.forEach(System.err::println);}
limit 1
@Testpublic void selectByWrapper9(){ // 创建条件构造器 QueryWrapperqueryWrapper = Wrappers.query(); queryWrapper.in("age", Arrays.asList(30, 31, 32)) .last("limit 1"); // last 方法存在 sql 注入的风险 // 根据条件构造器进行查询 List users = userMapper.selectList(queryWrapper); users.forEach(System.err::println);}
@Testpublic void selectByWrapperLambda(){ // LambdaQueryWrapperlambdaQueryWrapper = new LambdaQueryWrapper(); // LambdaQueryWrapper lambdaQueryWrapper = new QueryWrapper ().lambda(); LambdaQueryWrapper lambdaQueryWrapper = Wrappers.lambdaQuery(); lambdaQueryWrapper.like(User::getName, "雨").lt(User::getAge, 40); // 根据条件构造器进行查询 List users = userMapper.selectList(lambdaQueryWrapper); users.forEach(System.err::println);}
@Testpublic void selectByWrapperChain(){ Listusers = new LambdaQueryChainWrapper ( userMapper ) .like(User::getName, "雨") .lt(User::getAge, 40) .list(); users.forEach(System.err::println);}
select id,name from user where name like ‘雨%’ and age < 40
@Testpublic void selectByWrapper10(){ // 创建条件构造器 QueryWrapperqueryWrapper = Wrappers.query(); queryWrapper.select("id", "name") .like("name", "雨") .lt("age", 40); // 数据库表字段名 // 根据条件构造器进行查询 List users = userMapper.selectList(queryWrapper); users.forEach(System.err::println);}
select id,name,age,email from user where name like ‘雨%’ and age < 40
@Testpublic void selectByWrapper11(){ // 创建条件构造器 QueryWrapperqueryWrapper = Wrappers.query(); queryWrapper.select(User.class, u->!u.getColumn().equals("create_time") &&!u.getColumn().equals("manager_id")) .like("name", "雨") .lt("age", 40); // 数据库表字段名 // 根据条件构造器进行查询 List users = userMapper.selectList(queryWrapper); users.forEach(System.err::println);}
@Testpublic void selectByWrapper12(){ String name = "雨"; String email = ""; // 创建条件构造器 QueryWrapperqueryWrapper = Wrappers.query(); queryWrapper.like(StringUtils.isNotBlank(name), "name", name) .like(StringUtils.isNotBlank(email), "email", email); // 数据库表字段名 // 根据条件构造器进行查询 List users = userMapper.selectList(queryWrapper); users.forEach(System.err::println);}
where name=‘李艺伟’ and age=28
@Testpublic void selectByWrapper13(){ User user = new User(); user.setName("李艺伟"); user.setAge(28); // 创建条件构造器 QueryWrapperqueryWrapper = Wrappers.query(user); // 根据条件构造器进行查询 List users = userMapper.selectList(queryWrapper); users.forEach(System.err::println);}
注意: 默认为等值查询,如果需要模糊查询,需要在实体类的属性中添加注解
@TableField(condition = SqlCondition.LIKE)
例如:
@TableField(condition = SqlCondition.LIKE)private String name;
@Testpublic void selectByWrapperAllEq(){ Map map =new HashMap(); map.put("name", "大boss"); map.put("email", null); // 创建条件构造器 QueryWrapperqueryWrapper = Wrappers.query(); // 1.全匹配 // queryWrapper.allEq(map); // 2.设置为 false 时,如果参数为 null,则参数会排除,不作为查询条件 // queryWrapper.allEq(map, false); // 3.通过函数,排除某些字段作为查询条件;例如:排除 name 字段作为查询条件 queryWrapper.allEq((k,v)->!k.equals("name"), map); // 根据条件构造器进行查询 List users = userMapper.selectList(queryWrapper); users.forEach(System.err::println);}
@Testpublic void selectByWrapperMaps(){ // 创建条件构造器 QueryWrapperqueryWrapper = Wrappers.query(); queryWrapper.select("id", "name") .like("name", "雨") .lt("age", 40); // 数据库表字段名 // 根据条件构造器进行查询 List
SELECT AVG(age) avg_age, MIN(age) min_age, MAX(age) max_age
FROM user GROUP BY manager_id HAVING SUM(age) < 500
@Testpublic void selectByWrapperMaps2(){ // 创建条件构造器 QueryWrapperqueryWrapper = Wrappers.query(); queryWrapper.select("AVG(age) avg_age", "MIN(age) min_age", "MAX(age) max_age") .groupBy("manager_id") .having("SUM(age) < {0}", 500); // 数据库表字段名 // 根据条件构造器进行查询 List
@Testpublic void selectByWrapperObjs(){ QueryWrapperqueryWrapper = Wrappers.query(); queryWrapper.select("id", "name") .like("name", "雨") .lt("age", 40); // 数据库表字段名 // 根据条件构造器进行查询 List
注意:不能指定字段
@Testpublic void selectByWrapperCount(){ QueryWrapperqueryWrapper = Wrappers.query(); queryWrapper.like("name", "雨") .lt("age", 40); // 数据库表字段名 // 根据条件构造器进行查询 Integer count = userMapper.selectCount(queryWrapper); System.out.println("总记录数:"+count);}
注意:查询结果有多条时,会报错
@Testpublic void selectByWrapperOne(){ QueryWrapperqueryWrapper = Wrappers.query(); queryWrapper.like("name", "张雨琪") .lt("age", 40); // 数据库表字段名 // 根据条件构造器进行查询 User user = userMapper.selectOne(queryWrapper); System.out.println(user);}
dao/UserMapper.java
package org.example.dao;import com.baomidou.mybatisplus.core.conditions.Wrapper;import com.baomidou.mybatisplus.core.mapper.BaseMapper;import com.baomidou.mybatisplus.core.toolkit.Constants;import org.apache.ibatis.annotations.Param;import org.apache.ibatis.annotations.Select;import org.example.entity.User;import java.util.List;public interface UserMapper extends BaseMapper{ /** * 根据条件构造器进行查询 * */ @Select("select * from user ${ew.customSqlSegment}") public List selectByWrapper(@Param(Constants.WRAPPER) Wrapper wrapper);}
AppTest.java
@Testpublic void selectByWrapperSQL(){ LambdaQueryWrapperlambdaQueryWrapper = Wrappers.lambdaQuery(); lambdaQueryWrapper.like(User::getName, "雨").lt(User::getAge, 40); // 根据条件构造器进行查询 List users = userMapper.selectByWrapper(lambdaQueryWrapper); users.forEach(System.err::println);}
application.yml
配置 mybatis-plus 的 mapper 文件目录# mybatis-plusmybatis-plus: # mapper 目录 mapper-locations: classpath*:mapper/*Mapper.xml
resources/mapper/UserMapper.xml
(resources 资源目录下)dao/UserMapper.java
package org.example.dao;import com.baomidou.mybatisplus.core.conditions.Wrapper;import com.baomidou.mybatisplus.core.mapper.BaseMapper;import com.baomidou.mybatisplus.core.toolkit.Constants;import org.apache.ibatis.annotations.Param;import org.apache.ibatis.annotations.Select;import org.example.entity.User;import java.util.List;public interface UserMapper extends BaseMapper{ /** * 根据条件构造器进行查询,SQL 语句配置在 XML 文件中 * */ public List selectByWrapperXML(@Param(Constants.WRAPPER) Wrapper wrapper);}
AppTest.java
@Testpublic void selectByWrapperSQL2(){ LambdaQueryWrapperlambdaQueryWrapper = Wrappers.lambdaQuery(); lambdaQueryWrapper.like(User::getName, "雨").lt(User::getAge, 40); // 根据条件构造器进行查询 List users = userMapper.selectByWrapperXML(lambdaQueryWrapper); users.forEach(System.err::println);}
mybatis 分页仅实现了逻辑分页,即将数据全部加载到内存,然后再分页。
config/MybatisPlusConfig.java
package org.example.config;import com.baomidou.mybatisplus.annotation.DbType;import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.transaction.annotation.EnableTransactionManagement;@Configuration@EnableTransactionManagementpublic class MybatisPlusConfig { /** * 新的分页插件,一缓和二缓遵循mybatis的规则, * 需要设置 MybatisConfiguration#useDeprecatedExecutor = false * 避免缓存出现问题(该属性会在旧插件移除后一同移除) */ @Bean public MybatisPlusInterceptor mybatisPlusInterceptor() { MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.H2)); return interceptor; } @Bean public ConfigurationCustomizer configurationCustomizer() { return configuration -> configuration.setUseDeprecatedExecutor(false); }}
AppTest.java
@Testpublic void selectByWrapperPage(){ LambdaQueryWrapperlambdaQueryWrapper = Wrappers.lambdaQuery(); lambdaQueryWrapper.gt(User::getAge, 20); // 分页查询 // Page page = new Page<>(1, 3); // IPage iPage = userMapper.selectPage(page, lambdaQueryWrapper); // Map Page page = new Page<>(1, 3); IPage
Pagepage = new Page<>(1, 3, false);
dao/UserMapper.java
package org.example.dao;import com.baomidou.mybatisplus.core.conditions.Wrapper;import com.baomidou.mybatisplus.core.mapper.BaseMapper;import com.baomidou.mybatisplus.core.metadata.IPage;import com.baomidou.mybatisplus.core.toolkit.Constants;import com.baomidou.mybatisplus.extension.plugins.pagination.Page;import org.apache.ibatis.annotations.Param;import org.apache.ibatis.annotations.Select;import org.example.entity.User;import java.util.List;public interface UserMapper extends BaseMapper{ /** * 分页查询 * */ public IPage selectUserPage(Page page, @Param(Constants.WRAPPER) Wrapper wrapper);}
resources/mapper/UserMapper.xml
(resources 资源目录下)AppTest.java
@Testpublic void selectByWrapperPage2(){ LambdaQueryWrapperlambdaQueryWrapper = Wrappers.lambdaQuery(); lambdaQueryWrapper.gt(User::getAge, 20); // 分页查询 Page page = new Page<>(1, 3); IPage iPage = userMapper.selectUserPage(page, lambdaQueryWrapper); // 输出结果 System.err.println("当前页:"+iPage.getCurrent()); System.err.println("总页数:"+iPage.getPages()); System.err.println("总记录数:"+iPage.getTotal()); iPage.getRecords().forEach(System.err::println);}
AppTest.java
@Testpublic void insert(){ User user = new User(); user.setName("李小龙"); user.setAge(22); user.setEmail("lxl@163.com"); user.setManagerId(1088248166370832385L); user.setCreateTime(LocalDateTime.now()); // 插入数据 int num = userMapper.insert(user); System.err.println("影响记录数据:"+num); System.err.println("主键:"+user.getId());}
@Testpublic void updateById(){ User user = new User(); user.setId(1094592041087729666L); user.setAge(31); // 更新数据 int num = userMapper.updateById(user); System.err.println("影响记录数据:"+num);}
@Testpublic void updateByWrapper(){ // 条件构造器 UpdateWrapper updateWrapper = new UpdateWrapper(); updateWrapper.eq("name", "刘红雨"); // 更新实体对象 User user = new User(); user.setAge(34); // 更新数据 int num = userMapper.update(user,updateWrapper); System.err.println("影响记录数据:"+num);}
@Testpublic void updateByWrapper2(){ // 条件构造器 /*UpdateWrapperupdateWrapper = new UpdateWrapper(); updateWrapper.eq("name", "刘红雨").set("age", 30);*/ // Lambda 条件构造器 LambdaUpdateWrapper lambdaUpdateWrapper = Wrappers.lambdaUpdate(); lambdaUpdateWrapper.eq(User::getName, "刘红雨").set(User::getAge, 30); // set 方法设置修改的值 // 更新数据 int num = userMapper.update(null,lambdaUpdateWrapper); System.err.println("影响记录数据:"+num); // 链式编程 boolean isUpdate = new LambdaUpdateChainWrapper (userMapper) .eq(User::getName, "刘红雨") .set(User::getAge, 30) .update(); System.err.println("更新成功:"+isUpdate);}
@Testpublic void deleteById(){ Long userid = 1359388531205722114L; // 删除数据 int num = userMapper.deleteById(userid); System.err.println("影响记录数据:"+num);}
@Testpublic void deleteByMap(){ Mapmap =new HashMap<>(); map.put("name", "刘红雨"); map.put("age", 30); // 删除数据 int num = userMapper.deleteByMap(map); System.err.println("影响记录数据:"+num);}@Testpublic void deleteByBatchId(){ List ids = Arrays.asList(123123123123L, 1233435234534L); // 删除数据 int num = userMapper.deleteBatchIds(ids); System.err.println("影响记录数据:"+num);}
@Testpublic void deleteByBWrapper(){ LambdaQueryWrapperlambdaQueryWrapper = Wrappers.lambdaQuery(); lambdaQueryWrapper.eq(User::getId, 12312312312312L); // 删除数据 int num = userMapper.delete(lambdaQueryWrapper); System.err.println("影响记录数据:"+num);}
百度百科:
具体操作
com.baomidou.mybatisplus.extension.activerecord.Model
(当前为 User)com.baomidou.mybatisplus.core.mapper.BaseMapper
的 Mapper
(当前为 UserMapper)entity/UserMapper.java
package org.example.entity;import com.baomidou.mybatisplus.extension.activerecord.Model;import lombok.Data;import java.time.LocalDateTime;/*** * 员工实体类 * */@Datapublic class User extends Model { // 用户 ID private Long id; // 姓名 private String name; // 年龄 private Integer age; // 邮箱 private String email; // 上级领导 ID private Long managerId; // 创建时间 private LocalDateTime createTime;}
ARTest.java
@Testpublic void arSelect(){ User user = new User(); // 查询数据 Listusers = user.selectAll(); // 循环输出 users.forEach(System.err::println);}@Testpublic void arInsert(){ User user = new User(); user.setName("路飞"); user.setAge(25); user.setEmail("lf@163.com"); user.setManagerId(1088248166370832385L); user.setCreateTime(LocalDateTime.now()); // 新增数据 boolean isInsert = user.insert(); System.out.println("新增成功:"+isInsert);}@Testpublic void arUpdate(){ User user = new User(); user.setId(1359800186100056065L); user.setName("路飞飞"); // 修改数据 boolean isUpdate = user.updateById(); System.out.println("更新成功:"+isUpdate);}@Testpublic void arDelete(){ User user = new User(); user.setId(1359800186100056065L); // 删除数据 boolean isDelete = user.deleteById(); System.out.println("删除成功:"+isDelete);}
com.baomidou.mybatisplus.annotation.IdType.java
IdType | 说明 |
---|---|
AUTO(0) | 数据库 ID 自增 |
NONE(1) | 该类型为未设置主键类型 (注解里等于跟随全局,全局里约等于 INPUT) |
INPUT(2) | 用户输入 ID; |
ASSIGN_ID(3) | 分配ID (主键类型为number或string);默认 雪花算法 |
ASSIGN_UUID(4) | 分配UUID (主键类型为 string) |
全局策略配置
resources/application.yml
# mybatis-plusmybatis-plus: # 全局主键配置 global-config: db-config: id-type: assign_id
MP配置官网文档:
com.baomidou.mybatisplus.extension.service.IService
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
4.0.0 org.example mp-demo 1.0-SNAPSHOT mp-demo http://www.example.com UTF-8 1.8 1.8 spring-boot-starter-parent org.springframework.boot 2.1.3.RELEASE org.springframework.boot spring-boot-starter org.springframework.boot spring-boot-starter-test test org.projectlombok lombok true com.baomidou mybatis-plus-boot-starter 3.4.2 com.baomidou mybatis-plus 3.4.2 mysql mysql-connector-java junit junit 4.12 test maven-clean-plugin 3.1.0 maven-resources-plugin 3.0.2 maven-compiler-plugin 3.8.0 maven-surefire-plugin 2.22.1 maven-jar-plugin 3.0.2 maven-install-plugin 2.5.2 maven-deploy-plugin 2.8.2 maven-site-plugin 3.7.1 maven-project-info-reports-plugin 3.0.0
# mysql 连接配置spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/mp-db?useSSL=false&serverTimezone=GMT%2B8 username: root password: root2020# 输入日志,查看 sql 语句logging: level: root: warn org.example.dao: trace pattern: console: '%p%m%n'# mybatis-plusmybatis-plus: # mapper 目录 mapper-locations: classpath*:mapper/*Mapper.xml # 全局主键配置 global-config: db-config: id-type: assign_id
转载地址:http://mznws.baihongyu.com/