springboot使用了pageHelper一直报空指针异常

在这里插入图片描述
没有使用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);
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值