对List进行手动分页处理(数据量下的情况下使用)
public static <T> List<T> getPageList(List<T> list,Integer page,Integer pageSize){
if (CollectionUtils.isEmpty(list)){
return Collections.emptyList();
}
int count = list.size();
int listPageNum = 0;
if (count % pageSize == 0){
listPageNum = count / pageSize;
}else {
listPageNum = count / pageSize + 1;
}
int fromIndex = 0;
int endIndex = 0;
if (page > listPageNum || page < 1){
return Collections.emptyList();
}
if (page != listPageNum){
fromIndex = (page -1) * pageSize;
endIndex = fromIndex + pageSize;
}else {
fromIndex = (page -1) * pageSize;
endIndex = count;
}
List<T> pageList = list.subList(fromIndex,endIndex);
return pageList;
}