在spring boot启动类中 一定要加入以下代码
@Bean
PageHelper pageHelper(){
//分页插件
PageHelper pageHelper = new PageHelper();
Properties properties = new Properties();
properties.setProperty("reasonable", "true");
properties.setProperty("supportMethodsArguments", "true");
properties.setProperty("returnPageInfo", "check");
properties.setProperty("params", "count=countSql");
pageHelper.setProperties(properties);
//添加插件
new SqlSessionFactoryBean().setPlugins(new Interceptor[]{pageHelper});
return pageHelper;
}
分页样例
public Result listDocuments(String userId,String docTitle, String docSecretLevel, String docLevelId, String docClassifyId, String docStatus, Integer pageNo, Integer pageSize){
PageHelper.startPage(pageNo, pageSize);
List<DocDocumentVO> docDocumentVOList = docMapper.listDocuments(userId,docTitle,docSecretLevel,docLevelId,docClassifyId,docStatus);
PageInfo<DocDocumentVO> pageInfo = new PageInfo<DocDocumentVO>(docDocumentVOList);
return CallbackResult.getSuccessResult(pageNo,pageInfo.getTotal(),docDocumentVOList);
}
pom文件引入包5.0以下
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>4.1.1</version>
</dependency>