1 /** 2 * list分页展示 3 */ 4 public List<ChecklistDto> getListPage(int page, int pageSize, List<ChecklistDto> list) { 5 if (list == null || list.size() == 0) { 6 throw new ServiceException("分页数据不能为空!"); 7 } 8 int totalCount = list.size(); 9 page = page - 1; 10 int fromIndex = page * pageSize; 11 //分页不能大于总数 12 if(fromIndex>=totalCount) { 13 throw new ServiceException("页数或分页大小不正确!"); 14 } 15 16 int toIndex = ((page + 1) * pageSize); 17 if (toIndex > totalCount) { 18 toIndex = totalCount; 19 } 20 return list.subList(fromIndex, toIndex); 21 } 22 23 /** 24 * 返回总页数 25 */ 26 public int getPages(List<ChecklistDto> obj,Integer pageSize){ 27 int count = obj.size()/pageSize; 28 if(obj.size() == 0){ 29 return 0; 30 } 31 if(obj.size() <= pageSize){ 32 return 1; 33 }else if(count % pageSize == 0){ 34 return count; 35 }else { 36 return count + 1; 37 } 38 39 }