Java PageRequest 构造函数已被弃用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44848653/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PageRequest constructors have been deprecated
提问by end-user
I'm working the Spring Data Commons v2+ snapshot, and I see that the constructors for a PageRequest
have been deprecated. This appears to have occurred between M1& M2. Unfortunately, this is the only [real] implementation of the Pageable
interface. I'm wondering where the effort is heading, and what a better alternative would be for current development.
我正在处理 Spring Data Commons v2+ 快照,我发现 a 的构造函数PageRequest
已被弃用。这似乎发生在M1和M2之间。不幸的是,这是该Pageable
接口的唯一[真实] 实现。我想知道努力的方向是什么,对于当前的发展来说,更好的选择是什么。
采纳答案by Veluria
It's just the constructors which have been deprecated. Instead of
这只是已被弃用的构造函数。代替
new PageRequest(firstResult, maxResults, new Sort(...))
you can now use
你现在可以使用
PageRequest.of(firstResult, maxResults, Sort.by(...))
and that's it.
就是这样。
回答by Feroz Mujawar
You can use the following solution to solve your problem:
您可以使用以下解决方案来解决您的问题:
Page<User> users=userService.findByUserType(id,PageRequest.of(1, 3));
回答by driveall
We can use PageRequest.of(offset, limit)
instead of new PageRequest(offset, limit)
.
In this case we don't need to use deprecated constructor.
我们可以使用PageRequest.of(offset, limit)
代替new PageRequest(offset, limit)
. 在这种情况下,我们不需要使用已弃用的构造函数。