@Data
class Page {
private Long pageSize;
private Long currentPage;
private Long total;
}
// 分页
public Object pagination(List list,Long pageNum,Long pageSize){
Map<String,Object> map = new HashMap<>();
Page page = new Page();
page.setPageSize(pageSize);
page.setCurrentPage(pageNum);
page.setTotal(Long.valueOf(list.size()));
map.put("page",page);
if (pageNum == null && pageSize == null){
return list;
}
long startIndex = (pageNum.longValue() - 1) * pageSize.longValue();
long endIndex = pageNum.longValue() * pageSize.longValue() -1;
if (endIndex > list.size()-1){
endIndex = list.size()-1;
}
List<Object> finalList = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
if (i < startIndex){
continue;
}
if (i > endIndex){
break;
}
finalList.add(list.get(i));
}
map.put("result",finalList);
return map;
}
简单记录一个分页
最新推荐文章于 2024-08-19 17:55:12 发布