zoukankan      html  css  js  c++  java
  • List类型的集合转换为Page类型的方法

    参考:
    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";
    }
  • 相关阅读:
    IOC
    软件问题
    POJO和JavaBean
    tail命令
    实现质数遍历并输出所需时间
    完数
    break、continue
    *各种形状
    for、while、do-while
    jenkins实现maven项目自动化部署tomcat
  • 原文地址:https://www.cnblogs.com/zouhong/p/14337382.html
Copyright © 2011-2022 走看看