springboot整合PageHelper分页失效(架包导入正确)

 刚使用PageHelper做分页时,遇到的一个平时没注意的点,导致分页不生效。分享出来给以后遇到类似问题的小伙伴一个参考

1.首先确保架包引用正确

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

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

2.有坑的代码

 PageHelper.startPage(pageNum, 10);
            List<Task> taskList = projectServe.getMyTask(userName, timeOne, timeTwo, status, projectId, 1);//查询接口

3.解决后的代码

PageHelper.startPage(pageNum, 10);
        List<Task> myTask = projectMapper.getMyTaskList(userName, beginTime, endTime, status,projectId);

4原因

PageHelper.statPage(page,pageSize),这个配置一定要放在在你要分页的Mapper语句上,而不是逻辑接口上。当一个方法中有多个查询语句时,只有紧跟在PageHelper.starPage()方法后的查询结果才会分页

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
在Spring Boot项目中集成PageHelper分页插件的步骤如下: 1. 打开Maven库,找到com.github.pagehelper:pagehelper-spring-boot-starter。 2. 确定需要使用的版本号,比如1.4.1。 3. 在项目的pom.xml文件中添加PageHelper的依赖。可以使用如下代码: ``` <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.4.1</version> </dependency> ``` 4. 在application.properties或application.yml配置文件中进行配置,添加以下属性: ``` # 开启分页支持 pagehelper.helper-dialect=mysql pagehelper.reasonable=true pagehelper.support-methods-arguments=true pagehelper.params=count=countSql ``` 这里的配置是针对MySQL数据库的,如果你使用的是其他数据库,需要根据对应的数据库类型进行配置。 5. 在需要分页的Mapper方法上使用PageHelper.startPage方法来开启分页功能。例如: ``` @Mapper public interface UserMapper { List<User> getUsers(); } ``` 在UserMapper接口中的方法上加上注解@Select,并在方法内部使用PageHelper.startPage方法开启分页,如下所示: ``` @Select("SELECT * FROM user") List<User> getUsers(); ``` 6. 运行项目,分页功能就会生效。 通过以上步骤,你就可以在Spring Boot项目中成功集成PageHelper分页插件了。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [springboot整合分页插件PageHelper](https://blog.csdn.net/weixin_42408447/article/details/117528795)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [Springboot集成pagehelper 分页插件](https://blog.csdn.net/weixin_58696998/article/details/124397756)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值