我有在Spring Boot中将List转换为Page的业务逻辑。
在该代码中,我的可分页排序不会在输出中排序。
如果我可以通过可分页排序或从pageable. getSort()排序列表,有没有办法?
>
注意:我正在使用new PageImpl()将List转换为Page。*
int start=(int)pageable. getOffset();int end=(start pageable.getPageSize())
我实际上得到了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.
您使用pageImpl就像在新页面中设置变量一样,因此页面中的内容不排序。
你得到sorted=true,因为在可分页中你设置了sort。
如果您希望对页面中的内容进行排序,您应该在设置PageImpl之前使用Collection. sort对List内容进行排序。
原来PageImpl无法对数据进行排序。因此必须通过集合或任何其他API手动对其进行排序。