没有使用pagehelper接口能正常运行,但是使用了就报空指针异常,找了好久原因,最后从版本问题来解决,用了一系列pagehelper-spring-boot-starter,依然包空指针
如:
<!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper-spring-boot-starter -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.4.1</version>
</dependency>
然后导入pageHepler空指针解决了,但是查询的是所有的,分页没成功
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.0.0</version>
</dependency>
最后经过n多小时痛苦死磨烂打,根据一个大佬的方法得到解决.https://ask.csdn.net/questions/7397880
因为项目引入了spring security,所以User对象里面要加上getAuthorities方法,使用PageHelper.startPage(page.getPage(), page.getCount(), page.getOrderBy());进行分页的时候底层有个操作是将user对象里面的属性put进map的操作,但是getRole()为空值,一开始我没有加上判断空操作,导致到authorities的时候报错了
最后附上pageHelper的配置和使用
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
使用:直接在你要分页的查询语句上写上即可:
PageHelper.startPage(currentPage,size);