springboot 集成 pagehelper分页插件
pom
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.5</version>
</dependency>
yml
#mysql
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
#sqlserver
pagehelper:
helperDialect: sqlserver
reasonable: true
supportMethodsArguments: true
params: count=countSql
//只需要在查询的方法前 插入PageHelper.startPage() 就会自动分页
public Result getDraftEntry(int page,int size, int userId){
//下面的第三个参数为固定写法,"要排序的属性 正序还是倒叙"
//如果多个字段排序,逗号隔开,注意字段必须是数据库中的字段
PageHelper.startPage(page,size,"approve_state desc , id desc");
List<DictionaryEntry> list = dictionaryEntryService.findEntryByCreatorId(userId);
return list.size()>0?Result.success("查询成功",list):Result.success("查询到0条",list);
}

本文介绍了如何在SpringBoot项目中集成PageHelper分页插件,通过配置pom.xml和application.yml文件实现对MySQL和SQLServer的分页支持。在查询方法前加入PageHelper.startPage()即可自动完成分页,简化了开发过程。
906

被折叠的 条评论
为什么被折叠?



