1.导入分页插件
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.13</version>
</dependency>
2.mapper接口
List<Category> selectList();
3.xml
<select id="selectList" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from imooc_mall_category
</select>
4.service
PageInfo listForAdmin(Integer pageNum, Integer pageSize);
5.实现类
@Override
public PageInfo listForAdmin(Integer pageNum,Integer pageSize){
PageHelper.startPage(pageNum,pageSize,"type,order_num");
List<Category> categoryList = categoryMapper.selectList();
PageInfo pageInfo = new PageInfo(categoryList);
return pageInfo;
}
6.controller
/*
* 后台目录列表
* */
@ApiOperation("后台目录列表")
@PostMapping("admin/category/list")
@ResponseBody
public ApiRestResponse listCategoryForAdmin(@RequestParam Integer pageNum,
@RequestParam Integer pageSize){
PageInfo pageInfo = categoryService.listForAdmin(pageNum, pageSize);
return ApiRestResponse.success(pageInfo);
}
测试!!!
{
"status": 10000,
"msg": "SUCCESS",
"data": {
"total": 19,
"list": [
{
"id": 3,
"name": "新鲜水果",
"type": 1,
"parentId": 0,
"orderNum": 1,
"createTime": "2019-12-17T17:17:00.000+0000",
"updateTime": "2019-12-28T09:11:26.000+0000"
},
{
"id": 5,
"name": "海鲜水产",
"type": 1,
"parentId": 0,
"orderNum": 2,
"createTime": "2019-12-17T17:17:00.000+0000",
"updateTime": "2019-12-28T08:25:20.000+0000"
},
{
"id": 6,
"name": "精选肉类",
"type": 1,
"parentId": 0,
"orderNum": 3,
"createTime": "2019-12-17T17:17:00.000+0000",
"updateTime": "2019-12-28T08:25:21.000+0000"
},
{
"id": 9,
"name": "冷饮冻食",
"type": 1,
"parentId": 0,
"orderNum": 4,
"createTime": "2019-12-20T05:45:28.000+0000",
"updateTime": "2019-12-28T08:25:22.000+0000"
},
{
"id": 10,
"name": "蔬菜蛋品",
"type": 1,
"parentId": 0,
"orderNum": 5,
"createTime": "2019-12-20T05:45:28.000+0000",
"updateTime": "2019-12-28T08:25:23.000+0000"
},
{
"id": 27,
"name": "美味菌菇",
"type": 1,
"parentId": 0,
"orderNum": 7,
"createTime": "2019-12-20T05:45:28.000+0000",
"updateTime": "2020-02-10T15:20:36.000+0000"
},
{
"id": 4,
"name": "橘子橙子",
"type": 2,
"parentId": 3,
"orderNum": 1,
"createTime": "2019-12-17T17:17:00.000+0000",
"updateTime": "2019-12-28T08:25:10.000+0000"
},
{
"id": 7,
"name": "螃蟹",
"type": 2,
"parentId": 5,
"orderNum": 1,
"createTime": "2019-12-17T17:17:00.000+0000",
"updateTime": "2019-12-28T08:25:15.000+0000"
},
{
"id": 17,
"name": "冰淇淋",
"type": 2,
"parentId": 9,
"orderNum": 1,
"createTime": "2019-12-17T17:17:00.000+0000",
"updateTime": "2019-12-28T08:25:18.000+0000"
},
{
"id": 16,
"name": "牛羊肉",
"type": 2,
"parentId": 6,
"orderNum": 1,
"createTime": "2019-12-17T17:17:00.000+0000",
"updateTime": "2019-12-28T08:25:18.000+0000"
}
],
"pageNum": 1,
"pageSize": 10,
"size": 10,
"startRow": 1,
"endRow": 10,
"pages": 2,
"prePage": 0,
"nextPage": 2,
"isFirstPage": true,
"isLastPage": false,
"hasPreviousPage": false,
"hasNextPage": true,
"navigatePages": 8,
"navigatepageNums": [
1,
2
],
"navigateFirstPage": 1,
"navigateLastPage": 2,
"lastPage": 2,
"firstPage": 1
}
}
json格式化解析后
"status":10000, "msg":"SUCCESS", "data":{ "total":19, "list":Array[10], "pageNum":1, "pageSize":10, "size":10, "startRow":1, "endRow":10, "pages":2, "prePage":0, "nextPage":2, "isFirstPage":true, "isLastPage":false, "hasPreviousPage":false, "hasNextPage":true, "navigatePages":8, "navigatepageNums":[ 1, 2 ], "navigateFirstPage":1, "navigateLastPage":2, "lastPage":2, "firstPage":1 } }