网上查了半天也没有找到直接对List进行分页的,看了下PageInfo和Page的源码,还是自己整个简单的方法就行了。
/**
* 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;
}