MyBatisPlus框架:一文带你清晰整个MP框架逻辑 这个章节中将会回顾MyBatisPlus + SpringBoot的基本框架
主要依照以下几个原则
代码会同步在我的gitee中去,觉得不错的同学记得一键三连求关注,感谢:
Session-链接: MyBatisPlus_Demo
MyBatis-Plus (opens new window)(简称 MP)是一个 MyBatis (opens new window)的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发、提高效率而生。
其实就是进一步封装了JDBC,在Mybatis的基础上,对CRUD操作进行处理,对用户更友好,使用更快捷
无侵入:只做增强不做改变,引入它不会对现有工程产生影响,如丝般顺滑
损耗小:启动即会自动注入基本 CURD,性能基本无损耗,直接面向对象操作
强大的 CRUD 操作:内置通用 Mapper、通用 Service,仅仅通过少量配置即可实现单表大部分 CRUD 操作,更有强大的条件构造器,满足各类使用需求
支持 Lambda 形式调用:通过 Lambda 表达式,方便的编写各类查询条件,无需再担心字段写错
支持主键自动生成:支持多达 4 种主键策略(内含分布式唯一 ID 生成器 - Sequence),可自由配置,完美解决主键问题
支持 ActiveRecord 模式:支持 ActiveRecord 形式调用,实体类只需继承 Model 类即可进行强大的 CRUD 操作
支持自定义全局通用操作:支持全局通用方法注入( Write once, use anywhere )
内置代码生成器:采用代码或者 Maven 插件可快速生成 Mapper 、 Model 、 Service 、 Controller 层代码,支持模板引擎,更有超多自定义配置等您来使用
内置分页插件:基于 MyBatis 物理分页,开发者无需关心具体操作,配置好插件之后,写分页等同于普通 List 查询
分页插件支持多种数据库:支持 MySQL、MariaDB、Oracle、DB2、H2、HSQL、SQLite、Postgre、SQLServer 等多种数据库
内置性能分析插件:可输出 SQL 语句以及其执行时间,建议开发测试时启用该功能,能快速揪出慢查询
内置全局拦截插件:提供全表 delete 、 update 操作智能分析阻断,也可自定义拦截规则,预防误操作
#支持数据库
CREATE TABLE `god` (
`id` BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT '神仙id',
`name` VARCHAR(20) NOT NULL COMMENT '神仙name',
`Energy` BIGINT(20) NOT NULL COMMENT '战斗力',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=INNODB AUTO_INCREMENT = 1;
INSERT INTO account(NAME, Energy) VALUES ('神仙', 1000);
INSERT INTO account(NAME, Energy) VALUES ('大王', 1000);
SELECT * FROM god;
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
<version>5.1.47</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.3</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
还有对应的test依赖, lombok、日志等
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
这里的命名空间
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
parent标签,标识这是SpringBoot项目
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.12.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
JDK用的是1.8
<properties>
<java.version>8</java.version>
</properties>
配置DATASOURCE
配置服务端口
配置服务名称
server:
port: 8082
spring:
application:
name: IronTree
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/blog?useSSL=false&useUnicode=true&characterEncoding=UTF-8
username: root
password: root
@TableName(value = "god")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class God {
@TableId(type = IdType.AUTO)
private Integer id;
@TableField("name")
private String name;
@TableField("Energy")
private int Money;
}
@Repository
public interface GodMapper extends BaseMapper<God> {
}
接口封装了大量方法,对应了SQL 的 CRUD操作
而这里又对应了IService 接口
default boolean save(T entity) {
return SqlHelper.retBool(getBaseMapper().insert(entity));
}
/**
* 判断数据库操作是否成功
*
* @param result 数据库操作返回影响条数
* @return boolean
*/
public static boolean retBool(Integer result) {
return null != result && result >= 1;
}
这些都是通过SQLHelper实现的
public final class SqlHelper {
/**
* 主要用于 service 和 ar
*/
public static SqlSessionFactory FACTORY;
/**
@MapperScan("com.IronTree.Mapper")
扫描@MapperScan("com.IronTree.Mapper")
扫描Mapper文件@MapperScan("com.IronTree.Mapper")
@SpringBootApplication
public class MyBatisPlusApplication {
public static void main(String[] args) {
SpringApplication.run(MyBatisPlusApplication.class, args);
}
}
@Service
public interface GodService extends IService<God> {
}
@Service
public class GodServiceImpl extends ServiceImpl<GodMapper, God> implements GodService {
}
这里是真正的实现,也是通过BaseMapper
来进行操纵的
测试
@SpringBootTest
public class TestService {
@Resource
private GodService godService;
@Test
public void testServiceDemo1(){
God god = godService.getById(1);
System.out.println(god);
}
}
现在,SpringBoot+MP的基本框架已经搭建好了
基本的CRUD操作
@SpringBootTest
class MyBatisPlusApplicationTests {
@Resource
private GodMapper godMapper;
@Before
public void BeforeMp(){
System.out.println("开始测试");
}
@After
public void AfterMp(){
System.out.println("结束测试");
}
@Test
public void testSelect(){
List<God> gods = godMapper.selectList(null);
gods.forEach(s->{
System.out.println(s);
});
}
@Test
public void testInsert(){
God god = new God("Create蓝熊精",501);
int insert = godMapper.insert(god);
System.out.println(insert);
System.out.println(god);
}
@Test
public void testUpdate(){
God god = new God(7,"update白熊精",101);
int id = godMapper.updateById(god);
System.out.println(id);
System.out.println(god);
}
}
List gods = godMapper.selectList(null);
/**
* 根据 entity 条件,查询全部记录
*
* @param queryWrapper 实体对象封装操作类(可以为 null)
*/
List<T> selectList(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper);
这里的Wrapper就是条件查询器,负责一些复杂操作,后面讲
selectList
方法就是说进行,查询当前所有数据,返回值为List
int insert = godMapper.insert(god);
/**
* 插入一条记录
*
* @param entity 实体对象
*/
int insert(T entity);
在这里插入代码片
int id = godMapper.updateById(god);
/**
* 根据 ID 修改
*
* @param entity 实体对象
*/
int updateById(@Param(Constants.ENTITY) T entity);
/**
* 根据 ID 删除
*
* @param id 主键ID
*/
int deleteById(Serializable id);
部分结果展示
JDBC Connection [HikariProxyConnection@1638472859 wrapping com.mysql.jdbc.JDBC4Connection@17092fff] will not be managed by Spring
==> Preparing: INSERT INTO god ( name, Energy ) VALUES ( ?, ? )
==> Parameters: 黑熊精(String), 500(Integer)
<== Updates: 1
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@30c1da48]
1
God(id=5, name=黑熊精, Money=500)
在yaml文件中加入
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
public class God {
@TableId(type = IdType.AUTO)
private Integer id;
}
存在多种ID类型,
@TableId(type = IdType.AUTO)
@Getter
public enum IdType {
/**
* 数据库ID自增
* 该类型请确保数据库设置了 ID自增 否则无效
*/
AUTO(0),
/**
* 该类型为未设置主键类型(注解里等于跟随全局,全局里约等于 INPUT)
*/
NONE(1),
/**
* 用户输入ID
* 该类型可以通过自己注册自动填充插件进行填充
*/
INPUT(2),
/* 以下3种类型、只有当插入对象ID 为空,才自动填充。 */
/**
* 分配ID (主键类型为number或string),
* 默认实现类 {@link com.baomidou.mybatisplus.core.incrementer.DefaultIdentifierGenerator}(雪花算法)
*
* @since 3.3.0
*/
ASSIGN_ID(3),
/**
* 分配UUID (主键类型为 string)
* 默认实现类 {@link com.baomidou.mybatisplus.core.incrementer.DefaultIdentifierGenerator}(UUID.replace("-",""))
*/
ASSIGN_UUID(4);
private final int key;
IdType(int key) {
this.key = key;
}
}
我们后面插入两个字段
private Date createTime;
private Date updateTime;
我们在数据库中可以直接通过设置类型为TimeStamp的方式,同时选择自动更新,即可
现在我们可以通过MP从业务层面进行处理
@TableField(fill = FieldFill.INSERT)
private Date createTime;
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date updateTime;
开启自动填充功能
@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
@Override
public void insertFill(MetaObject metaObject) {
log.debug("insert Fill...");
this.setFieldValByName("createTime", new Date(), metaObject);
this.setFieldValByName("updateTime", new Date(), metaObject);
}
@Override
public void updateFill(MetaObject metaObject) {
log.debug("update Fill...");
this.setFieldValByName("updateTime", new Date(), metaObject);
}
}
在拦截器中配置相应的服务字段,即可
乐观锁在我 Redis专栏中 仔细介绍过
概念定义就不说了
@Version
@TableField("version")
private Integer Version;
@MapperScan("com.IronTree.Mapper")
@EnableTransactionManagement
@Configuration
public class MyBatisPlusConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
return interceptor;
}
}
@Test
public void testOptismisticLocker(){
/**
* 判断版本号不一致
**/
God god = godMapper.selectById(8);
god.setName("Locker白熊精8");
god.setMoney(1086);
god.setVersion(2);
godMapper.updateById(god);
/**
* 判断版本号一致:可以修改
**/
/* God god = godMapper.selectById(7);
god.setName("Locker白熊精");
god.setMoney(1086);
godMapper.updateById(god);*/
}
发现第一个Version发生变化,所以不会修改
God god = godMapper.selectById(8);
god.setName("Locker白熊精8");
god.setMoney(1086);
god.setVersion(2);
godMapper.updateById(god);
如果Version不变,会被修改
God god = godMapper.selectById(7);
god.setName("Locker白熊精");
god.setMoney(1086);
godMapper.updateById(god);*/
}
@MapperScan("com.IronTree.Mapper")
@EnableTransactionManagement
@Configuration
public class MyBatisPlusConfig {
/**
* 关于MP分页规则说明
* 规则: 需要设定一个拦截器.将分页的Sql进行动态的拼接.
* Sql: 规则现在的Sql都支持Sql92标准!!!! 设计理念不同
*/
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.H2));
return interceptor;
}
}
@Test
public void testPage(){
Page<God> page = new Page<>(1, 5);
godMapper.selectPage(page,null);
page.getRecords().forEach(System.out::println);
System.out.println("getTotal: " + page.getTotal());
QueryWrapper<God> objectQueryWrapper = new QueryWrapper<>();
}
分页器本身就是limit,封装了很多API方法使用
结果展示
JDBC Connection [HikariProxyConnection@1766451528 wrapping com.mysql.jdbc.JDBC4Connection@210d2a6c] will not be managed by Spring
==> Preparing: SELECT COUNT(*) FROM god
==> Parameters:
<== Columns: COUNT(*)
<== Row: 14
<== Total: 1
==> Preparing: SELECT id,name,Energy AS Money,version,create_time,update_time FROM god LIMIT ?
==> Parameters: 5(Long)
<== Columns: id, name, Money, version, create_time, update_time
<== Row: 1, 托塔天王, 2800, 1, 2022-12-14 11:27:40.0, 2022-12-14 11:28:04.0
<== Row: 2, 陈塘关哪吒, 1000, 1, 2022-12-14 11:27:40.0, 2022-12-14 11:28:04.0
<== Row: 3, 黑熊精, 500, 1, 2022-12-14 11:27:40.0, 2022-12-14 11:28:04.0
<== Row: 7, Locker白熊精, 1086, 1, 2022-12-14 11:27:40.0, 2022-12-14 12:42:57.0
<== Row: 8, 黑熊精, 500, 1, 2022-12-14 11:27:40.0, 2022-12-14 11:28:04.0
<== Total: 5
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@313f8301]
God(id=1, name=托塔天王, Money=2800, Version=1, createTime=Wed Dec 14 11:27:40 CST 2022, updateTime=Wed Dec 14 11:28:04 CST 2022)
God(id=2, name=陈塘关哪吒, Money=1000, Version=1, createTime=Wed Dec 14 11:27:40 CST 2022, updateTime=Wed Dec 14 11:28:04 CST 2022)
God(id=3, name=黑熊精, Money=500, Version=1, createTime=Wed Dec 14 11:27:40 CST 2022, updateTime=Wed Dec 14 11:28:04 CST 2022)
God(id=7, name=Locker白熊精, Money=1086, Version=1, createTime=Wed Dec 14 11:27:40 CST 2022, updateTime=Wed Dec 14 12:42:57 CST 2022)
God(id=8, name=黑熊精, Money=500, Version=1, createTime=Wed Dec 14 11:27:40 CST 2022, updateTime=Wed Dec 14 11:28:04 CST 2022)
getTotal: 14
接口方法的参数中,会出现各种 Wrapper,比如 queryWrapper、updateWrapper 等。Wrapper 的作用就是用于定义各种各样的条件(where)。所以不管是查询、更新、删除都会用到Wrapper。
wrapper就是一个条件构造器,可以通过API方法配置Mapper接口实现数据库的CRUD复杂操作
QueryWrapper(LambdaQueryWrapper) 和 UpdateWrapper(LambdaUpdateWrapper) 的父类
用于生成 sql 的 where 条件, entity 属性也用于生成 sql 的 where 条件
注意: entity 生成的 where 条件与 使用各个 api 生成的 where 条件没有任何关联行为
@Test
public void testWrapper1(){
QueryWrapper<God> Wrapper = new QueryWrapper<>();
Wrapper.isNotNull("create_time")
.isNotNull("update_time")
.ge("Energy", 501);
List<God> gods = godMapper.selectList(Wrapper);
}
JDBC Connection [HikariProxyConnection@440307236 wrapping com.mysql.jdbc.JDBC4Connection@4ed4a7e4] will not be managed by Spring
==> Preparing: SELECT id,name,Energy AS Money,version,create_time,update_time FROM god WHERE (create_time IS NOT NULL AND update_time IS NOT NULL AND Energy >= ?)
==> Parameters: 501(Integer)
<== Columns: id, name, Money, version, create_time, update_time
<== Row: 1, 托塔天王, 2800, 1, 2022-12-14 11:27:40.0, 2022-12-14 11:28:04.0
<== Row: 2, 陈塘关哪吒, 1000, 1, 2022-12-14 11:27:40.0, 2022-12-14 11:28:04.0
<== Row: 7, Locker白熊精, 1086, 1, 2022-12-14 11:27:40.0, 2022-12-14 12:42:57.0
<== Row: 9, 白熊精, 1000, 1, 2022-12-14 11:27:40.0, 2022-12-14 11:28:04.0
<== Row: 17, Create蓝熊精, 501, 1, 2022-12-14 11:59:15.0, 2022-12-14 11:59:15.0
<== Total: 5
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@fb2e3fd]
@Test
public void testWrapper2(){
QueryWrapper<God> Wrapper = new QueryWrapper<>();
Wrapper.eq("name", "黑熊精");
List<God> gods = godMapper.selectList(Wrapper);
}
JDBC Connection [HikariProxyConnection@805536380 wrapping com.mysql.jdbc.JDBC4Connection@29b40b3] will not be managed by Spring
==> Preparing: SELECT id,name,Energy AS Money,version,create_time,update_time FROM god WHERE (name = ?)
==> Parameters: 黑熊精(String)
<== Columns: id, name, Money, version, create_time, update_time
<== Row: 3, 黑熊精, 500, 1, 2022-12-14 11:27:40.0, 2022-12-14 11:28:04.0
<== Row: 8, 黑熊精, 500, 1, 2022-12-14 11:27:40.0, 2022-12-14 11:28:04.0
<== Row: 10, 黑熊精, 500, 1, 2022-12-14 11:27:40.0, 2022-12-14 11:28:04.0
<== Total: 3
@Test
public void testWrapper3(){
QueryWrapper<God> Wrapper = new QueryWrapper<>();
Wrapper.between("Energy", "50","501");
List<God> gods = godMapper.selectList(Wrapper);
}
JDBC Connection [HikariProxyConnection@1005400853 wrapping com.mysql.jdbc.JDBC4Connection@119b0892] will not be managed by Spring
==> Preparing: SELECT id,name,Energy AS Money,version,create_time,update_time FROM god WHERE (Energy BETWEEN ? AND ?)
==> Parameters: 50(String), 501(String)
<== Columns: id, name, Money, version, create_time, update_time
<== Row: 3, 黑熊精, 500, 1, 2022-12-14 11:27:40.0, 2022-12-14 11:28:04.0
<== Row: 8, 黑熊精, 500, 1, 2022-12-14 11:27:40.0, 2022-12-14 11:28:04.0
<== Row: 10, 黑熊精, 500, 1, 2022-12-14 11:27:40.0, 2022-12-14 11:28:04.0
<== Row: 11, 白熊精, 500, 1, 2022-12-14 11:27:40.0, 2022-12-14 11:28:04.0
<== Row: 12, 花熊精, 500, 1, 2022-12-14 11:37:51.0, 2022-12-14 11:37:51.0
<== Row: 14, Create蓝熊精, 500, 1, 2022-12-14 11:53:30.0, null
<== Row: 15, Create蓝熊精, 500, 1, 2022-12-14 11:55:51.0, null
<== Row: 16, Create蓝熊精, 501, 1, 2022-12-14 11:56:46.0, null
<== Row: 17, Create蓝熊精, 501, 1, 2022-12-14 11:59:15.0, 2022-12-14 11:59:15.0
<== Total: 9
@Test
public void testWrapper4(){
QueryWrapper<God> Wrapper = new QueryWrapper<>();
Wrapper.between("Energy", "50","501")
.like("name","白");
List<God> gods = godMapper.selectList(Wrapper);
}
JDBC Connection [HikariProxyConnection@1339858954 wrapping com.mysql.jdbc.JDBC4Connection@513b52af] will not be managed by Spring
==> Preparing: SELECT id,name,Energy AS Money,version,create_time,update_time FROM god WHERE (Energy BETWEEN ? AND ? AND name LIKE ?)
==> Parameters: 50(String), 501(String), %白%(String)
<== Columns: id, name, Money, version, create_time, update_time
<== Row: 11, 白熊精, 500, 1, 2022-12-14 11:27:40.0, 2022-12-14 11:28:04.0
<== Total: 1
@Test
public void testWrapper6(){
QueryWrapper<God> Wrapper = new QueryWrapper<>();
Wrapper.between("Energy", "50","500")
.notLike("name","黑")
.likeRight("name","C");
List<Map<String, Object>> maps = godMapper.selectMaps(Wrapper);
System.out.println(maps);
}
JDBC Connection [HikariProxyConnection@1136503323 wrapping com.mysql.jdbc.JDBC4Connection@30b975ad] will not be managed by Spring
==> Preparing: SELECT id,name,Energy AS Money,version,create_time,update_time FROM god WHERE (Energy BETWEEN ? AND ? AND name NOT LIKE ? AND name LIKE ?)
==> Parameters: 50(String), 500(String), %黑%(String), C%(String)
<== Columns: id, name, Money, version, create_time, update_time
<== Row: 14, Create蓝熊精, 500, 1, 2022-12-14 11:53:30.0, null
<== Row: 15, Create蓝熊精, 500, 1, 2022-12-14 11:55:51.0, null
<== Total: 2
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@106d77da]
[{Money=500, create_time=2022-12-14 11:53:30.0, name=Create蓝熊精, id=14, version=1}, {Money=500, create_time=2022-12-14 11:55:51.0, name=Create蓝熊精, id=15, version=1}]
@Test
public void testWrapper5(){
QueryWrapper<God> Wrapper = new QueryWrapper<>();
Wrapper.inSql("id", "select id from god where id < 7")
.orderByDesc("id");
List<God> gods = godMapper.selectList(Wrapper);
}
==> Preparing: SELECT id,name,Energy AS Money,version,create_time,update_time FROM god WHERE (id IN (select id from god where id < 7)) ORDER BY id DESC
==> Parameters:
<== Columns: id, name, Money, version, create_time, update_time
<== Row: 3, 黑熊精, 500, 1, 2022-12-14 11:27:40.0, 2022-12-14 11:28:04.0
<== Row: 2, 陈塘关哪吒, 1000, 1, 2022-12-14 11:27:40.0, 2022-12-14 11:28:04.0
<== Row: 1, 托塔天王, 2800, 1, 2022-12-14 11:27:40.0, 2022-12-14 11:28:04.0
<== Total: 3
代码总览
@SpringBootTest
class MyBatisPlusWrapperTests {
@Resource
private GodMapper godMapper;
@Before
public void BeforeMp(){
System.out.println("开始测试");
}
@After
public void AfterMp(){
System.out.println("结束测试");
}
@Test
public void testWrapper1(){
QueryWrapper<God> Wrapper = new QueryWrapper<>();
Wrapper.isNotNull("create_time")
.isNotNull("update_time")
.ge("Energy", 501);
List<God> gods = godMapper.selectList(Wrapper);
}
@Test
public void testWrapper2(){
QueryWrapper<God> Wrapper = new QueryWrapper<>();
Wrapper.eq("name", "黑熊精");
List<God> gods = godMapper.selectList(Wrapper);
}
@Test
public void testWrapper3(){
QueryWrapper<God> Wrapper = new QueryWrapper<>();
Wrapper.between("Energy", "50","501");
List<God> gods = godMapper.selectList(Wrapper);
}
@Test
public void testWrapper4(){
QueryWrapper<God> Wrapper = new QueryWrapper<>();
Wrapper.between("Energy", "50","501")
.like("name","白");
List<God> gods = godMapper.selectList(Wrapper);
}
@Test
public void testWrapper5(){
QueryWrapper<God> Wrapper = new QueryWrapper<>();
Wrapper.inSql("id", "select id from god where id < 7")
.orderByDesc("id");
List<God> gods = godMapper.selectList(Wrapper);
}
@Test
public void testWrapper6(){
QueryWrapper<God> Wrapper = new QueryWrapper<>();
Wrapper.between("Energy", "50","500")
.notLike("name","黑")
.likeRight("name","C");
List<Map<String, Object>> maps = godMapper.selectMaps(Wrapper);
System.out.println(maps);
}
}
https://gitee.com/baomidou/mybatis-plus
https://baomidou.com/pages
因为SQL有点老了,所以删了,重新更新了下, 这里遇到了插入的汉字为???
所以更新下我的处理方法
SHOW VARIABLES LIKE 'char%';
SET character_set_server = utf8;
[client]
default-character-set=utf8
[mysqld]
character-set-server=utf8
url: jdbc:mysql://localhost:3306/blog?useSSL=false&useUnicode=true&characterEncoding=UTF-8