说明
项目使用Mybatis作为持久化框架时,我们可以使用一些别人再次封装的一些插件来提高开发效率,使用较多的如通用mapper,PageHelper等,这次介绍一个更好用的插件Mybatis-Plus,感觉这个比较像通用mapper+PageHelper,并且分页方面还可以选出总条数。
Mybatis-plus官网->https://baomidou.gitee.io/mybatis-plus-doc/#/
快速开始
首先给出项目结构
1 初始化和配置
首先更新pom.xml
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.1.2</version>
</dependency>
2 配置application.yml
server:
port: 8082
mybatis-plus:
mapper-locations: classpath:mapper/*.xml
global-config:
# 关闭MP3.0自带的banner
banner: false
db-config:
# 默认数据库表下划线命名
table-underline: true
3 编写application.java 添加分页配置
package cn.yunlingfly.springbootmybatisplus;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.my