SpringBoot整合Pagehelper
- 一、引入依赖
- 二、配置 application.yml
- 三、配置 MybatisPlusConfig
- 四、Controller
- 五、ServiceImpl
一、引入依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.4.1</version>
</dependency>
二、配置 application.yml
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);
paginationInnerInterceptor.setMaxLimit(5000L);
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));
}