spring cloud工程添加mybatis分页插件

本文介绍如何在SpringCloud项目中添加MyBatis分页插件PageHelper,包括配置依赖、设置参数及在Controller或Service层实现分页查询的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

spring cloud工程添加mybatis分页插件

###1.在pom文件中加入依赖

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

###2.在配置文件application.yml或application.properties中加入如下代码

#mybatis分页      
pagehelper:
    helperDialect: db2
    reasonable: true
    supportMethodsArguments: true
    params: count=countSql

###3.在controller层或service层方法调用前加上如下代码(说明:current为前端传的当前页数,pageSize为页大小)

int current=1, pageSize=10;
if(reqMap.containsKey("current") && null != reqMap.get("current")) {
	current = Integer.valueOf(reqMap.get("current").toString());
}
if(reqMap.containsKey("pageSize") && null != reqMap.get("pageSize")) {
	pageSize = Integer.valueOf(reqMap.get("pageSize").toString());
}
PageHelper.startPage(current,pageSize);
Page<CustEssence> list = custEssenceMapper.selectCustEssencePage(reqMap);
PageInfo<CustEssence> pageInfo = new PageInfo<CustEssence>(list);
	List<CustEssence> rtnlist = pageInfo.getList();
	return rtnlist;
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值