public class MyPageHelper {
public static <T> IPage<T> startPage(List<T> ts, Integer currentPage, Integer pageSize) {
IPage<T> page = new Page<>(currentPage, pageSize);
int start = (currentPage - 1) * pageSize;
int end = currentPage * pageSize - 1;
int total = ts.size();
if (end >= total) {
end = total - 1;
}
ArrayList<T> records = new ArrayList<>();
for (int i = start; i <= end; i++) {
records.add(ts.get(i));
}
page.setRecords(records);
page.setTotal(total);
return page;
}
}```
```java
@GetMapping("configList")
public R<?> configList(Query query) {
List<ApproveConfig> configs = approveConfigService.list();
List<ApproveConfigVO> vos = configs.stream().map(r -> {
ApproveConfigVO approveConfigVO = new ApproveConfigVO();
approveConfigVO.setId(r.getId());
approveConfigVO.setApplyType(r.getApplyType());
approveConfigVO.setApproveDep(r.getApproveDep());
approveConfigVO.setApproveConfigJsons(linkedJson2List(r.getConfigJson()));
return approveConfigVO;
}).collect(Collectors.toList());
IPage<ApproveConfigVO> approveConfigVOIPage = MyPageHelper.startPage(vos, query.getCurrent(), query.getSize());
return R.data(approveConfigVOIPage);
}```
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/83568.html