PageUtils
2020-11-10 本文已影响0人
BySjm
public class PageUtils {
public static List startPage(List list, Integer pageNum, Integer pageSize) {
if (list == null) {
return Lists.newArrayList();
}
if (list.size() == 0) {
return Lists.newArrayList();
}
//记录总数
Integer count = list.size();
//页数
Integer pageCount = 0;
if (count % pageSize == 0) {
pageCount = count / pageSize;
} else {
pageCount = count / pageSize + 1;
}
//开始索引
int fromIndex = 0;
//结束索引
int toIndex = 0;
if (pageNum > pageCount) {
pageNum = pageCount;
}
if (!pageNum.equals(pageCount)) {
fromIndex = (pageNum - 1) * pageSize;
toIndex = fromIndex + pageSize;
} else {
fromIndex = (pageNum - 1) * pageSize;
toIndex = count;
}
List pageList = list.subList(fromIndex, toIndex);
return pageList;
}
}