pagehelper是常用的分页插件,代码中常用到,使用简便且对代码侵入性较小,很多人都喜欢使用。不过有时会遇到分页失败问题,输出结果没有分页,日志输出sql语句没有分页关键字及分页参数,目测是pagehelper插件直接未起作用。此类情况总结起来一般是一下几种问题引起:
- springboot项目中应导入的包pagehelper与springboot的整合包:
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
</dependency>
直接用pagehelper的包可能无效:
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
</dependency>
-
pagehelper的分页作用范围是PageHelper.startPage();之后的第一个查询,其他查询无效
-
版本适配问题,springboot版本过高时,低版本的pagehelper不具体版本对应详情可参考:项目首页 - pagehelper-spring-boot:pagehelper-spring-boot - GitCode
