参考:
public String e(@PageableDefault(size = 3, sort = {"updateTime"}, direction = Sort.Direction.DESC) Pageable pageable,
HttpSession session, Model model) {
User user = (User) session.getAttribute("user");
Integer userId = user.getId();
List<Object> list = new ArrayList<>();
List<Object> objectList = objectService.listMyPost();
for (object post : objectList) {
if (post.getUid().equals(userId)) {
list.add(post);
}
}
//当前页第一条数据在list中的位置
int start = (int) pageable.getOffset();
//当前页最后一条数据在list中的位置
int end = (start + pageable.getPageSize()) > list.size() ? list.size() : (start + pageable.getPageSize());
Page<object> List = new PageImpl<>(list.subList(start, end), pageable, list.size());
model.addAttribute("list", List);
return "index";
}