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;
}
posted @ 2022-08-27 07:25  漫点  阅读(474)  评论(0编辑  收藏  举报