1.在pom.xml中引入依赖
<!-- pagehelper -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.10</version>
<!-- 排除pagehelper中的mybatis依赖 -->
<exclusions>
<exclusion>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
</exclusion>
</exclusions>
</dependency>
2.在application.yml中做如下配置
# 分页配置
pagehelper:
helper-dialect: mysql
reasonable: true
support-methods-arguments: true
params: count=countSql
3.在代码中使用
PageHelper.startPage(pageNum, pageSize);
List<User> list= userMapper.getAllList();
PageInfo pageInfo = new PageInfo(list);