安装
pom.xml下配置
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.5</version>
</dependency>
application.yml配置
pagehelper:
helper-dialect: mysql # 指定数据库 可以不配置,插件会自动检测数据库的类型
reasonable: true #分页合理化 当该参数设置为 true 时,pageNum<=0 时会查询第一页, pageNum>pages(超过总数时),会查询最后一页。默认false 时,直接根据参数进行查询。
support-methods-arguments: true
pageSizeZero: false #为true时,第零页显示全部
params: count=countSqls
使用
踩雷
分页不生效
pom.xml依赖导入成了spring的
select语句位置错误
只有紧跟在 PageHelper.startPage 方法后的第一个 Mybatis 的查询(Select)方法会被分页。
在不清楚PagerHelper可以获取所有数目时还特意写了一个select语句统计全部数目,搜博客好久也没发现这个问题