我们可以从 Spring boot Pageable 中排序 List<T>

我有在 Spring Boot 中将 List 转换为 Page 的业务逻辑。


在该代码中,我的可分页排序不会在输出中排序。


如果我可以通过 pageable 排序或从 pageable.getSort() 排序列表,有没有办法?


注意:我正在使用 new PageImpl() 将列表转换为页面。*


int start = (int) pageable.getOffset(); int end = (start + pageable.getPageSize()) > List.size() ?List.size() : (start + pageable.getPageSize()); Page paginatedList = new PageImpl(floorsheetList.subList(start, end), pageable, list.size());


我实际上得到 sorted= true 但数据不会排序。


sort: {

sorted: true,

unsorted: false,

empty: false

}

更新


Turns out PageImpl cannot sort the data. So have to manually sort it via Collections or any other APIs.


慕慕森
浏览 293回答 2
2回答

慕姐8265434

事实证明 PageImpl 无法对数据进行排序。因此必须通过 Collections 或任何其他 API 手动对其进行排序。

POPMUISE

您使用 pageImpl 就像将变量设置到新页面中一样,因此页面中的内容不会排序。你得到 sorted = true 因为在 pageable 中你设置了排序。如果要对页面中的内容进行排序,则应在设置 PageImpl 之前使用 Collections.sort 对列表内容进行排序。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java