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";
    }
  • 相关阅读:
    显示多行字符串
    dowhile
    获取系统的相关文件夹
    DLL 实际应用版本
    ShellExecute
    LoadLibrary
    MFC DLL的创建
    在DLL中存放资源
    替换字符串
    RemoveDirectoryB
  • 原文地址:https://www.cnblogs.com/zouhong/p/14337382.html
Copyright © 2011-2022 走看看