// 自定义分页器 private Page<ProjectApplicationVO> getExchangePage(Page pageSource, List<ProjectInfoDO> resultLists) { // 当前页 Long current = pageSource.getCurrent(); // 每页数据条数 Long size = pageSource.getSize(); Page<ProjectApplicationVO> page = new Page<>(current, size); int count = resultLists.size(); List<ProjectInfoDO> pageList = new ArrayList<>(); //计算当前页第⼀条数据的下标 Long currId = current > 1 ? (current - 1) * size : 0; for (int i = 0; i < size && i < count - currId; i++) { pageList.add(resultLists.get((int) (currId + i))); } page.setSize(size); page.setCurrent(current); page.setTotal(count); //计算分页总页数 page.setPages(count % 10 == 0 ? count / 10 : count / 10 + 1); // 转换VO List resultList = pageList.stream().map(obj -> { ProjectApplicationVO VO = new ProjectApplicationVO(); BeanUtil.copyProperties(obj, VO); return VO; }).collect(Collectors.toList()); page.setRecords(resultList); return page; }
本文作者为DBC,转载请注明。