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 代码中是否格式正确,以下格式

Spring 中 PageHelper 不生效问题及解决方法

先调用 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

标签:Spring,PageHelper,不生效
0
投稿

猜你喜欢

  • java多线程-同步块实例讲解

    2022-06-21 02:10:41
  • Java遍历Map对象的四种方式

    2022-05-07 14:30:04
  • Redis监听过期的key实现流程详解

    2023-12-12 02:41:28
  • Springboot 扫描mapper接口的2种操作

    2022-08-04 03:28:54
  • Component和Configuration注解区别实例详解

    2022-04-17 01:12:24
  • pagehelper踩坑记之分页乱套问题解决

    2021-11-14 14:19:34
  • Java 如何实现时间控制

    2023-02-20 06:19:23
  • C#高级静态语言效率利器之泛型详解

    2023-01-24 09:18:02
  • java中Statement 与 PreparedStatement接口之间的关系和区别

    2023-11-25 03:11:11
  • java 二叉查找树实例代码

    2022-07-23 22:54:28
  • springboot 多数据源的实现(最简单的整合方式)

    2022-08-20 02:30:11
  • c# 委托的本质是什么

    2022-01-31 17:55:46
  • java弹幕小游戏1.0版本

    2021-12-06 04:42:48
  • 详解java并发之重入锁-ReentrantLock

    2021-08-03 03:58:08
  • Java实现的计算最大下标距离算法示例

    2022-02-09 19:14:37
  • nacos注册中心单节点ap架构源码解析(最新推荐)

    2022-09-02 09:31:43
  • C#设计模式之工厂模式

    2023-07-10 13:43:33
  • C# SqlHelper应用开发学习

    2023-05-07 11:07:35
  • JAVA设置手动提交事务,回滚事务,提交事务的操作

    2022-07-20 08:07:40
  • RocketMQ producer发送者浅析

    2023-04-03 06:35:32
  • asp之家 软件编程 m.aspxhome.com