页面排序不适用于零大小
我有以下代码:
PageRequest pageRequest = PageRequest.of(0, count, page.getSort());
当 count = 0 时,它不起作用,因为据我所知,排序不适用于 null。有没有办法用零大小来解决这个问题,或者我应该申请计算其他数字?
I have a following code:
PageRequest pageRequest = PageRequest.of(0, count, page.getSort());
With count = 0 it isn't working, because as I see the sorting won't work with null. Is there a way to solve this with a zero size or I should apply to count other number?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
count=0
,您的PageRequest
会转换为请求不带任何元素的排序集合。排序,事实上完整的请求没有任何意义,因此你不应该传递 0,这实际上是由代码验证的:
https://github.com/spring-projects/spring-data-commons/blob/8e5010c490459785316e8dc55817a9ff61227290/src/main/java/org/springframework/data/domain/AbstractPageRequest.java#L27
With
count=0
yourPageRequest
translate to requesting a sorted collection without any elements.Sorting and in fact the complete request doesn't make any sense, therefore you should not pass 0 and that is actually verified by the code:
https://github.com/spring-projects/spring-data-commons/blob/8e5010c490459785316e8dc55817a9ff61227290/src/main/java/org/springframework/data/domain/AbstractPageRequest.java#L27