我这里对集合进行分页实现是把所有的集合加载到内存,然后按照分页的模式,模拟实现分页效果。这种方式慎用,不到万不得已千万别用:
private List<CollaborationBill> pageList(List<CollaborationBill> collaborationBills, Integer pageNum, Integer pageSize) {
//当前页
int current = pageNum;
//每页数据条数
int size = pageSize;
int count = collaborationBills.size();
List<CollaborationBill> pageList = new ArrayList<>();
//计算当前页第一条数据的下标
int currId = current > 1 ? (current - 1) * size : 0;
for (int i = 0; i < size && i < count - currId; i++){
pageList.add(collaborationBills.get(currId + i));
}
return pageList;
}