分页
List<PushInfo> models = this.findByStatus(whCode, statusList,pushNum,2); if (models.isEmpty()) { return; } int pageSize = 500;// 条数 int listCount = models.size(); int totalPage = listCount % pageSize > 0 ? listCount / pageSize + 1 : listCount / pageSize; for (int i = 0; i < totalPage; i++) { List<PushInfo> modelList = pageBySubList(models, pageSize, i + 1); this.updateOutboundPushInfo(modelList); }
/** * 利用subList方法进行分页 * * @param list 分页数据 * @param pageSize 页面大小 * @param currentPage 当前页面 */ public List<PushInfo> pageBySubList(List<PushInfo> list, int pageSize, int currentPage) { int totalCount = list.size(); int pageCount = 0; List<PushInfo> subList; int m = totalCount % pageSize; if (m > 0) { pageCount = totalCount / pageSize + 1; } else { pageCount = totalCount / pageSize; } if (m == 0) { subList = list.subList((currentPage - 1) * pageSize, pageSize * (currentPage)); } else { if (currentPage == pageCount) { subList = list.subList((currentPage - 1) * pageSize, totalCount); } else { subList = list.subList((currentPage - 1) * pageSize, pageSize * (currentPage)); } } return subList; }