SpringBoot集成PageHelper及使用方法详解
添加分页插件依赖文件
注意:以下三个缺一不可
<!-- 分页插件pagehelper --> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>5.0.0</version> </dependency> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-autoconfigure</artifactId> <version>1.2.3</version> </dependency> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2.3</version> </dependency> <!-- 分页插件pagehelper -->
配置application.properties
这一步,是可选的
#pagehelper分页插件配置 #pagehelper.helperDialect=mysql #pagehelper.reasonable=true #pagehelper.supportMethodsArguments=true #pagehelper.params=count=countSql
使用
个人觉得原始的PageInfo即可满足需要。当然,可以按需封装。
package com.vue.admin.controller; @RestController @RequestMapping(value = "/sysUser") public class SysUserController { @Autowired private SysUserServie sysUserServieImpl; @RequestMapping(value="/select") public PageInfo select(@RequestBody Map map)throws Exception{ Integer currentPage = (Integer)map.get("currentPage"); Integer pageSize =(Integer) map.get("pageSize"); PageHelper.startPage(currentPage,pageSize); List<SysUser> list = sysUserServieImpl.selectByCondition(example); PageInfo<SysUser> appsPageInfo = new PageInfo<>(list); return appsPageInfo;//PageUtil.pageVO(); } }
报错及解决
java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.github.pagehelper.Page
原因:查询结果如果不是Page类型,强转成ArrayList当然会报错。这说明PageHelper没有生效。
解决:在我的项目中是因为少引入了pom.xml中的依赖,引入之后就解决了。网上也有说===没有打开EnableAutoConfiguration,所以需要手动@ImportAutoConfiguration(PageHelperAutoConfiguration.class),不然PageInterceptor 无法配置成功,也就无法正常进行sql拦截并进行对应分页处理。===这个估计用的是配置吧
到此这篇关于SpringBoot集成PageHelper及使用方法详解的文章就介绍到这了,更多相关SpringBoot集成PageHelper内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
解析ConcurrentHashMap: 预热(内部一些小方法分析)
ConcurrentHashMap是由Segment数组结构和HashEntry数组结构组成。Segment的结构和HashMap类似,是一种数组和链表结构,今天给大家普及java面试常见问题---ConcurrentHashMap知识,一起看看吧2021-06-06Java中stream处理中map与flatMap的比较和使用案例
这篇文章主要介绍了Java中stream处理中map与flatMap的比较和使用案例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2021-03-03Java 数据结构算法Collection接口迭代器示例详解
这篇文章主要为大家介绍了Java 数据结构算法Collection接口迭代器示例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪2022-09-09Spring中@Scheduled和HttpClient的连环坑
这篇文章主要给大家介绍了关于Spring中@Scheduled和HttpClient的连环坑,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧。2018-03-03
最新评论