Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PageRequest constructors have been deprecated

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.

like image 580
end-user Avatar asked Jun 30 '17 14:06

end-user


3 Answers

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.

like image 92
Steffen Avatar answered Oct 17 '22 12:10

Steffen


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

like image 13
driveall Avatar answered Oct 17 '22 12:10

driveall


You can use the following solution to solve your problem:

Page<User> users=userService.findByUserType(id,PageRequest.of(1, 3));
like image 10
Feroz Mujawar Avatar answered Oct 17 '22 11:10

Feroz Mujawar