java如何实现对List集合进行分页
对List集合进行分页:
private <T> Page<T> listToPage(List<T> dataList, Integer pageSize, Integer pageNumber){
Page<T> result = new Page<T>();
List<T> monitors = new ArrsyList<T>();
if(dataList!=null && dataList.size()>0){
int currentIndex = pageNumber>1?(pageNumber-1)*pageSize:0;
for(int i=0; i<pageSize &&i<dataList.size()-currentIndex;i++){
T data = dataList.get(currentIndex +i);
monitors.add(data);
}
result.addAll(monitors);
result.setTotal(dataList.size());
result.setPageNum(pageNumber);
result.setPageSize(pageSize);
result.setReasonable(true);
}
return result;
}
本文来自博客园,作者:漫点,转载请注明原文链接:https://www.cnblogs.com/mandian/p/16629752.html