mybatis分页插件_springBoot中两种配置mybatis分页插件方式
时间: 2023-07-25 11:26:40 浏览: 227
在 Spring Boot 中,可以使用两种方式配置 MyBatis 分页插件:
1. 使用 PageHelper 自动配置
PageHelper 是一个开源的 MyBatis 分页插件,支持多种数据库,使用起来非常方便。在 Spring Boot 中,可以使用 PageHelper 的自动配置功能,只需要在 pom.xml 中引入 PageHelper 依赖,然后在 application.properties 或 application.yml 中添加配置即可。
例如,在 pom.xml 中添加如下依赖:
```xml
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.13</version>
</dependency>
```
然后在 application.properties 或 application.yml 中添加如下配置:
```properties
# 开启分页插件
pagehelper.helperDialect=mysql
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql
```
2. 使用 MyBatis-Plus
MyBatis-Plus 是一个开源的 MyBatis 增强工具包,其中包含了分页插件。在 Spring Boot 中,可以使用 MyBatis-Plus 的自动配置功能,只需要在 pom.xml 中引入 MyBatis-Plus 依赖,然后在 application.properties 或 application.yml 中添加配置即可。
例如,在 pom.xml 中添加如下依赖:
```xml
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.1.2</version>
</dependency>
```
然后在 application.properties 或 application.yml 中添加如下配置:
```properties
# 开启分页插件
mybatis-plus.configuration.properties.pagehelper.helperDialect=mysql
```
阅读全文
相关推荐















