PageRequest constructors have been deprecated

Viewed 60033

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.

4 Answers

We can use PageRequest.of(offset, limit) instead of new PageRequest(offset, limit). In this case we don't need to use deprecated constructor.

You can use the following solution to solve your problem:

Page<User> users=userService.findByUserType(id,PageRequest.of(1, 3));

Since Spring v2.0: PageRequest.of() is a static method , you don't need to construct a new PageRequest() instance.

use this static methode for Creating a new unsorted PageRequest :

PageRequest.of(int page, int size)
Related