这里写自定义目录标题
关于PageHelper的使用的随手记录
导入依赖
com.github.pagehelper pagehelper-spring-boot-starter 1.3.0加入启动项上的注解
@SpringBootApplication(exclude = {
PageHelperAutoConfiguration.class
})
让springboot启动项的扫描排除PagehelperApplication.class(这样做的是为了避免出现,出现多个分页插件的问题,现在的含有了分页插件,当你使用pagehlper的依赖后,会出现多个,导致报错)
具体的使用
具体的使用 ,pagehelper的使用一定要注意最后的清空,因为他的原理是脏sql,如果不清空,会产生如果前一个sql的语句出错,那么这个pagehelper就会留到下一句sql导致下一句sql也报错。
PageInfo<CameraResponse> info = null;
try {
PageHelper.startPage(request.getPageNum(), request.getPageSize());
List<CameraResponse> dataList = cameraMapper.getList(request);
info = PageInfo.of(dataList);
} catch (Exception e) {
e.printStackTrace();
} finally {
PageHelper.clearPage();
}
return info;