public List manualPage(List list, Integer pageNum, Integer pageSize) {
if (CollectionUtils.isEmpty(list)) {
return list;
}
List newList = new ArrayList<>();
//总记录数
int total = list.size();
// 开始索引
int fromIndex = (pageNum - 1) * pageSize;
// 结束索引
int toIndex = fromIndex + pageSize;
// 如果结束索引大于集合的最大索引,那么规定结束索引=集合大小
toIndex = toIndex > total ? total : toIndex;
// 开始索引 大于 总记录数则返回空
newList = fromIndex > total ? newList : list.subList(fromIndex, toIndex);
return newList;
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)