pom.xml下载依赖
<dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper-spring-boot-starter</artifactId><version>1.4.7</version>
</dependency>
applicaiton.yml添加配置
pagehelper : helperDialect : mysqlreasonable : true supportMethodsArguments : true params : count=countSqlpageSizeZero : true
UserController.java
@GetMapping ( "/users" ) public PageInfo < UserBean > showUsers ( @RequestParam ( value = "pageNum" , defaultValue = "1" ) int pageNum, @RequestParam ( value = "pageSize" , defaultValue = "1" ) int pageSize) { System . out. println ( ":::" + pageNum + ":" + pageSize) ; PageHelper . startPage ( pageNum, pageSize) ; List < UserBean > users = userService. queryAllUser ( ) ; return new PageInfo < > ( users) ; }
请求 http://localhost:8081/api/users?pageSize=2&pageNum=3 返回结果
{
total : 6 ,
list : [
{
id : 22 ,
username : "myj22" ,
password : "45622"
} ,
{
id : 23 ,
username : "myj333" ,
password : "45633"
}
] ,
pageNum : 3 ,
pageSize : 2 ,
size : 2 ,
startRow : 5 ,
endRow : 6 ,
pages : 3 ,
prePage : 2 ,
nextPage : 0 ,
isFirstPage : false ,
isLastPage : true ,
hasPreviousPage : true ,
hasNextPage : false ,
navigatePages : 8 ,
navigatepageNums : [
1 ,
2 ,
3
] ,
navigateFirstPage : 1 ,
navigateLastPage : 3
}