003-SpringBoot整合Pagehelper
SpringBoot整合Pagehelper
一、引入依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.4.1</version>
</dependency>
二、配置 application.yml
# PageHelper分页插件
# springboot配置分页插件pageHelper和数据库方言的几种方式 : https://www.cnblogs.com/zhncnblogs/p/17972507
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
autoRuntimeDialect: true
三、配置 MybatisPlusConfig
@Configuration
@MapperScan("org.example.mapper*")
public class MybatisPlusConfig {
/**
* 分页插件
*/
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor(){
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(paginationInnerInterceptor());
return interceptor;
}
/**
* 分页插件,自动识别数据库类型
*/
public PaginationInnerInterceptor paginationInnerInterceptor() {
PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);
// 设置最大单页限制数量,默认 5000 条,-1 不受限制
paginationInnerInterceptor.setMaxLimit(5000L);
//查询时候查询页>总页数 返回数据方式 true调回到首页,false 继续请求
paginationInnerInterceptor.setOverflow(false);
return paginationInnerInterceptor;
}
}
四、Controller
@GetMapping("/listPage/{pageNum}/{pageSize}")
public ResultPageVo<List<BgateVehicleRegisterDto>> queryBgateVehicleRegisterByPage(
@PathVariable(name = "pageNum", required = true) Long currentPageNo,
@PathVariable(name = "pageSize", required = true) Integer pageSize) {
ResultPageVo<List<BgateVehicleRegisterDto>> re = ResultFactory.successPage();
Page<BgateVehicleRegisterDto> dataPage = new Page<>(currentPageNo, pageSize);
Map<String, String> map = MapUtil.convertString(request.getParameterMap());
IPage<BgateVehicleRegisterDto> resultPage = iBgateVehicleRegisterService.queryBgateVehicleRegisterByPage(dataPage, map);
re.setRows(resultPage.getRecords());
re.setTotal(resultPage.getTotal());
re.setCurrentPageNo(currentPageNo);
return re;
}
五、ServiceImpl
@Override
public IPage<BgateVehicleRegisterDto> queryBgateVehicleRegisterByPage(IPage<BgateVehicleRegisterDto> page, Map<String, String> paramMap) {
return bgateVehicleRegisterMapper.selectPage(page, Wrappers.lambdaQuery(BgateVehicleRegisterDto.class)
.eq(BgateVehicleRegisterDto::getStatus, 0));
}
原文地址:https://blog.csdn.net/xiaogang1226/article/details/144219422
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!