对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;
}
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/java/282457.html