/**
* 手动分页
* */
private Map handPage(Integer currentPage, Integer pageSize, List list) {
Map myPageMap = new HashMap();
try {
//todo 手动分页
//总数量
int total = list.size();
//第几行数据开始
int fromIndex = (Integer.valueOf(currentPage)-1)*Integer.valueOf(pageSize);
//第几行结束
int toIndex = fromIndex + Integer.valueOf(pageSize);
if (toIndex > total){
toIndex = total;
}
if (fromIndex <= total){
List pageList = list.subList(fromIndex, toIndex);
pageList.forEach(System.out::println);
myPageMap.put("total", total);
myPageMap.put("currentPage", currentPage);
myPageMap.put("pageSize", pageSize);
myPageMap.put("totalPages", (total - 1)/Integer.valueOf(pageSize) + 1);
myPageMap.put("records", pageList);
}
}catch (Exception e){
log.error("手动分页失败"+e.getMessage());
}
return myPageMap;
}
handPage工具类
于 2023-01-04 15:09:57 首次发布