<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的转换

        Conversion of List to Page in Spring(Spring中List到Page的转换)

          <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的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
                  • <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>
                      • <small id='yZOGA'></small><noframes id='yZOGA'>

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