一、引入 pagehelper 依赖
<!-- PageHelper 分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.5</version>
<exclusions>
<exclusion>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
</exclusion>
<exclusion>
<groupId>mybatis-spring</groupId>
<artifactId>org.mybatis</artifactId>
</exclusion>
</exclusions>
</dependency>
二、在 yml 配置文件中配置如下信息即可使用分页插件:
#分页设置
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
pageSizeZero: false #pageSize=0 返回所有
params: count=countSql
三、使用 pagehelper 进行分页查询
核心代码:
PageHelper.startPage(pageNum,pageSize);
PageInfo<PurchasePlan> pageInfoRes = new PageInfo<>(purchasePlanService.list());