/**
* pagehelper手动分页
* @param currentPage 当前页
* @param pageSize
* @param list
* @param <T>
* @return
*/
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;
}
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);
PageInfo<T> pageInfo = new PageInfo<>(page);
return pageInfo;
}
完成对List操作后,再手动使用PageInfo对List进行分页,保证分页信息正确
最新推荐文章于 2024-07-17 10:06:02 发布