SpringBoot项目中分页插件PageHelper无效的问题及解决方法
作者:Piconjo_Official 时间:2021-07-08 23:25:55
在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>
来源:https://blog.csdn.net/Piconjo/article/details/106127835
标签:SpringBoot,分页插件,PageHelper
0
投稿
猜你喜欢
Java设计模式中的命令模式
2023-11-20 04:26:46
详解Spring Bean的集合注入和自动装配
2023-02-18 15:02:58
Spring Boot修改启动端口的方法
2022-02-10 05:49:55
从最基本的Java工程搭建SpringMVC+SpringDataJPA+Hibernate
2023-05-31 20:37:20
c#中CAD文件读取实例
2023-07-23 19:37:59
Java使用BigDecimal进行运算封装的实际案例
2023-06-20 02:22:26
SpringMVC RESTFul实体类创建及环境搭建
2022-12-25 18:23:06
详解基于MVC的数据查询模块进行模糊查询
2022-02-13 19:26:49
深入理解Java设计模式之命令模式
2023-11-24 11:06:31
举例讲解Java中synchronized关键字的用法
2023-07-01 22:20:19
Java实现文件读取和写入过程解析
2023-06-28 11:35:36
Java——对象初始化顺序使用详解
2023-11-01 01:08:46
java实现简单的猜数字小游戏
2023-11-11 12:55:40
Intellij IDEA中启动多个微服务(开启Run Dashboard管理)
2022-01-11 02:25:00
Java8使用stream实现list中对象属性的合并(去重并求和)
2023-06-23 13:44:40
学会IDEA REST Client后就可以丢掉postman了
2023-11-10 15:32:56
IOS 实现摇一摇的操作
2023-07-02 13:46:53
Java Swing JTextArea文本区域的实现示例
2023-10-30 13:40:28
Springboot全局异常捕获及try catch区别解析
2022-03-02 17:44:07
java实现上传文件类型检测过程解析
2023-11-09 12:04:21