Mybatis-plus把List数据分页
作者:互联网
一、编写工具类:
/** * @project 工资条应用服务系统 * @Description 多表联查-分页 * @Author songwp * @Date 2022/8/8 10:31 * @Version 1.0.0 **/ public class PageUtils { public static Page getPages(Integer pageNo, Integer pageSize, List list){ Page page = new Page(); int size = list.size(); if(pageSize > size){ pageSize = size; } // 求出最大页数,防止currentPage越界 int maxPage = size % pageSize == 0 ? size / pageSize : size / pageSize + 1; if(pageNo > maxPage){ pageNo = maxPage; } // 当前页第一条数据下标 int currentIndex = pageNo > 1 ? (pageNo -1) * pageSize : 0; List pageList = new ArrayList<>(); // 将当前页的数据放进pageList for (int i = 0; i < pageSize && currentIndex + i < size; i++) { pageList.add(list.get(currentIndex + i)); } page.setCurrent(pageNo).setSize(pageSize).setTotal(list.size()).setRecords(pageList); return page; } }
二、调用测试数据显示:
{"records": [ { "year": "2022", "month": "2", "sendTime": "2022-08-05T10:48:13.000+0000", "haveSent": 4, "totalSend": 5, "totalSalary": 1000010.0, "uploadId": "1555505949937033218", "pushStatus": 1 } ], "total": "2", "size": "1", "current": "0", "orders": [], "optimizeCountSql": true, "searchCount": true, "countId": null, "maxLimit": null, "pages": "2" } }
标签:pageSize,pageNo,int,pageList,List,list,plus,Mybatis,size 来源: https://www.cnblogs.com/songweipeng/p/16561217.html