欢迎来到代码驿站!

JAVA代码

当前位置:首页 > 软件编程 > JAVA代码

SpringBoot项目中分页插件PageHelper无效的问题及解决方法

时间:2022-02-21 10:58:12|栏目:JAVA代码|点击:

在Springboot项目中使用分页插件的时候 发现PageHelper插件失效了

我导入的是:

后来才发

<dependency>
 <groupId>com.github.pagehelper</groupId>
 <artifactId>pagehelper</artifactId>
 <version>5.1.10</version>
</dependency>

现 PageHelper若要在Springboot中使用 是需要进行注入的:

@Configuration
public class mybatisConfiguration {
@Bean
public PageHelperpageHelper(){
System.out.println("MybatisConfiguration.pageHelper()");
 PageHelper pageHelper =new PageHelper();
 Properties properties =new Properties();
 properties.setProperty("offsetAsPageNum","true");
 properties.setProperty("rowBoundsWithCount","true");
 properties.setProperty("reasonable","true");
 pageHelper.setProperties(properties);
 return pageHelper;
 }
}

当然 也可使用Springboot PageHelper启动器 无需注入 开箱即用 更推荐此方法:

<dependency>
 <groupId>com.github.pagehelper</groupId>
 <artifactId>pagehelper-spring-boot-starter</artifactId>
 <version>1.2.10</version>
</dependency>

PS:SpringBoot项目和Spring项目依赖分页插件Pagehelper不起作用的问题

最近在SpringBoot项目和Spring项目同时开发,两个项目都依赖了Mybatis框架里的pagehelper分页插件,但是SpringBoot项目分页不起作用,一直查询出所有数据。

错误原因:两项目都引入的依赖为

 <dependency>
      <groupId>com.github.pagehelper</groupId>
      <artifactId>pagehelper</artifactId>
      <version>4.0.0</version>
    </dependency>

解决办法:经过多次调查试验,发现SpringBoot项目依赖的分页插件和Spring项目有所不同,需要spring-boot-starter下的包才可以。所以SpringBoot项目需要配置下面的依赖即可:

 <dependency>
      <groupId>com.github.pagehelper</groupId>
      <artifactId>pagehelper-spring-boot-starter</artifactId>
      <version>1.2.5</version>
    </dependency>

总结

上一篇:浅析Java 常用的 4 种加密方式(MD5+Base64+SHA+BCrypt)

栏    目:JAVA代码

下一篇:java数据结构基础:循环链表和栈

本文标题:SpringBoot项目中分页插件PageHelper无效的问题及解决方法

本文地址:http://www.codeinn.net/misctech/194128.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有