<tfoot id='zqKKI'></tfoot>

      <small id='zqKKI'></small><noframes id='zqKKI'>

      <legend id='zqKKI'><style id='zqKKI'><dir id='zqKKI'><q id='zqKKI'></q></dir></style></legend>

        <bdo id='zqKKI'></bdo><ul id='zqKKI'></ul>

      1. <i id='zqKKI'><tr id='zqKKI'><dt id='zqKKI'><q id='zqKKI'><span id='zqKKI'><b id='zqKKI'><form id='zqKKI'><ins id='zqKKI'></ins><ul id='zqKKI'></ul><sub id='zqKKI'></sub></form><legend id='zqKKI'></legend><bdo id='zqKKI'><pre id='zqKKI'><center id='zqKKI'></center></pre></bdo></b><th id='zqKKI'></th></span></q></dt></tr></i><div id='zqKKI'><tfoot id='zqKKI'></tfoot><dl id='zqKKI'><fieldset id='zqKKI'></fieldset></dl></div>
      2. Spring中List到Page的转换

        时间:2024-08-24

          <bdo id='1QT2y'></bdo><ul id='1QT2y'></ul>

              1. <tfoot id='1QT2y'></tfoot>

                  <small id='1QT2y'></small><noframes id='1QT2y'>

                    <tbody id='1QT2y'></tbody>
                  <legend id='1QT2y'><style id='1QT2y'><dir id='1QT2y'><q id='1QT2y'></q></dir></style></legend>
                  <i id='1QT2y'><tr id='1QT2y'><dt id='1QT2y'><q id='1QT2y'><span id='1QT2y'><b id='1QT2y'><form id='1QT2y'><ins id='1QT2y'></ins><ul id='1QT2y'></ul><sub id='1QT2y'></sub></form><legend id='1QT2y'></legend><bdo id='1QT2y'><pre id='1QT2y'><center id='1QT2y'></center></pre></bdo></b><th id='1QT2y'></th></span></q></dt></tr></i><div id='1QT2y'><tfoot id='1QT2y'></tfoot><dl id='1QT2y'><fieldset id='1QT2y'></fieldset></dl></div>
                  本文介绍了Spring中List到Page的转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试在春季将列表转换为页面.我已经使用

                  I am trying to convert list to page in spring. I have converted it using

                  new PageImpl(users, pageable, users.size());

                  new PageImpl(users, pageable, users.size());

                  但现在我遇到了排序和分页本身的问题.当我尝试传递大小和页面时,分页不起作用.

                  But now I having problem with sorting and pagination itself. When I try passing size and page, the pagination doesn't work.

                  这是我正在使用的代码.

                  Here's the code I am using.

                  我的控制器

                      public ResponseEntity<User> getUsersByProgramId(
                          @RequestParam(name = "programId", required = true) Integer programId Pageable pageable) {
                  
                      List<User> users = userService.findAllByProgramId(programId);
                      Page<User> pages = new PageImpl<User>(users, pageable, users.size());
                  
                      return new ResponseEntity<>(pages, HttpStatus.OK);
                  }
                  

                  这是我的用户回购

                  public interface UserRepo extends JpaRepository<User, Integer>{
                  
                  public List<User> findAllByProgramId(Integer programId);
                  

                  这是我的服务

                      public List<User> findAllByProgramId(Integer programId);
                  

                  推荐答案

                  我也遇到了同样的问题.我使用了子列表:

                  I had the same problem. I used subList:

                  final int start = (int)pageable.getOffset();
                  final int end = Math.min((start + pageable.getPageSize()), users.size());
                  final Page<User> page = new PageImpl<>(users.subList(start, end), pageable, users.size());
                  

                  这篇关于Spring中List到Page的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 Spring Data 中漂亮地更新 JPA 实体? 下一篇:PageRequest 构造函数已被弃用

                  相关文章

                • <i id='yZOGA'><tr id='yZOGA'><dt id='yZOGA'><q id='yZOGA'><span id='yZOGA'><b id='yZOGA'><form id='yZOGA'><ins id='yZOGA'></ins><ul id='yZOGA'></ul><sub id='yZOGA'></sub></form><legend id='yZOGA'></legend><bdo id='yZOGA'><pre id='yZOGA'><center id='yZOGA'></center></pre></bdo></b><th id='yZOGA'></th></span></q></dt></tr></i><div id='yZOGA'><tfoot id='yZOGA'></tfoot><dl id='yZOGA'><fieldset id='yZOGA'></fieldset></dl></div>
                      <bdo id='yZOGA'></bdo><ul id='yZOGA'></ul>
                  1. <small id='yZOGA'></small><noframes id='yZOGA'>

                    1. <legend id='yZOGA'><style id='yZOGA'><dir id='yZOGA'><q id='yZOGA'></q></dir></style></legend>
                      <tfoot id='yZOGA'></tfoot>