写了一个手动分页的功能,可以直接用,分享一下
/*
currentPage: 当前页数
pageSize:每页条数
list:要执行分页的数组
*/
public static <T> PageInfo<T> getPageInfo(int currentPage, int pageSize, List<T> list) {
int total = list.size();
if (total > pageSize) {
int toIndex = pageSize * currentPage;
if (toIndex > total) {
toIndex = total;
}
int totalPage = total % pageSize == 0 ? (total/pageSize) : (total/pageSize)+1;
if (totalPage < currentPage){
list = new ArrayList<>();
}else {
list = list.subList(pageSize * (currentPage - 1), toIndex);
}
}
Page<T> page = new Page<>(currentPage, pageSize);
page.addAll(list);
page.setPages((total + pageSize - 1) / pageSize);
page.setTotal(total);
return new PageInfo<>(page);
}