Spring 中 PageHelper 不生效问题及解决方法
作者:张学徒 时间:2021-11-25 11:25:04
使用这个插件时要注意版本的问题,不同的版本可能 PageHelper 不会生效
springboot 导入的 pagehelper 包
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.4.6</version>
</dependency>
如果导入的单个 pagehelper 依赖,还需要导入 pagehelper-spring-boot-autoconfigure 依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.3.2</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-autoconfigure</artifactId>
</dependency>
Pagehelper这个mybatis插件网上有很多使用的教程,但使用时往往会有个别一直报错的,或者项目起不来的,主要还是版本问题,之前忽略了这个问题,找了各种方法,在maven里引入pagehelper的依赖时,总是项目起不来,网上有很多资料,就是没有找到对症下药的解决方法,琢磨了挺久,无意间在一篇文章上提到版本不兼容问题,于是找了各种版本做对应,最终实现此功能,主要是springboot、mybatis、和Pagehelper插件的版本要对应上,下面我贴出我的这三个的版本。
引用:Pagehelper分页插件-Mybatis
注意 Java 代码中是否格式正确,以下格式
先调用 PageHelper.startPage(page, limit);
进行设置页码和条数,然后进行开始执行查询,最后用 PageInfo 类以这种类的数据格式进行返回。
本地 jar 包导入时
需要导入 pagehelper 和 jsqlparser 和 pagehelper-spring-boot-autoconfigure 这几个 jar 包,且版本差异要比较小,否则可能不能生效
在 maven 中添加以下内容,打包时添加 jar 包
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.*</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.*</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<!--打包jar-->
<directory>src/lib</directory>
<targetPath>/BOOT-INF/lib/</targetPath>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
</resources>
</build>
参考链接:【解决】PageHelper 分页不生效
来源:https://blog.csdn.net/qq_37280924/article/details/128332549
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
java多线程-同步块实例讲解
Java遍历Map对象的四种方式
Redis监听过期的key实现流程详解
![](https://img.aspxhome.com/file/2023/4/94324_0s.png)
Springboot 扫描mapper接口的2种操作
![](https://img.aspxhome.com/file/2023/6/73106_0s.jpg)
Component和Configuration注解区别实例详解
pagehelper踩坑记之分页乱套问题解决
Java 如何实现时间控制
C#高级静态语言效率利器之泛型详解
java中Statement 与 PreparedStatement接口之间的关系和区别
![](https://img.aspxhome.com/file/2023/9/60029_0s.png)
java 二叉查找树实例代码
springboot 多数据源的实现(最简单的整合方式)
c# 委托的本质是什么
![](https://img.aspxhome.com/file/2023/7/80077_0s.png)
java弹幕小游戏1.0版本
详解java并发之重入锁-ReentrantLock
Java实现的计算最大下标距离算法示例
nacos注册中心单节点ap架构源码解析(最新推荐)
![](https://img.aspxhome.com/file/2023/6/98116_0s.png)
C#设计模式之工厂模式
![](https://img.aspxhome.com/file/2023/4/83224_0s.jpg)