Issue
so im trying to implement pagination controller in my Springboot application i got this error (The constructor PageRequest(int, int) is undefined)(problem1) // +(add argument to match pagerequest(int,int,sort)to fix the problem but the sort class is protected so it saids that The constructor PageRequest(int, int, Sort) is not visible (problem2)
problem1 :
@GetMapping("/list")
@ResponseBody
public Page<Posts> Pagination(@RequestParam(defaultValue="0") int page) {
return PostsRepository.findAll(new PageRequest(page,4));
}
problem2:
@GetMapping("/list")
@ResponseBody
public Page<Posts> Pagination(@RequestParam(defaultValue="0") int page) {
return PostsRepository.findAll(new PageRequest(page,4,null));
}
Solution
As suggested by chrylis you can change your controller to use the Pageable argument. if thats not possible create pageable object and using page and size.
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "3") int size
Pageable paging = PageRequest.of(page, size);
Answered By - Nagaraju Chitimilla
Answer Checked By - Candace Johnson (JavaFixing Volunteer)