Ruwanka Madhushan Ruwanka Madhushan - 4 years ago 145
Java Question

How to get all results in one page using Spring Data Pagination

I want to get all the results in single page, I've tried with

Pageable p = new PageRequest(1, Integer.MAX_VALUE);
return customerRepository.findAll(p);


Above is not working, is there any methods to achieve this? Seems like it cannot be achieved from custom query as asked here.

Answer Source

Your page request is incorrect because you are looking for results at the wrong page. It should be:

new PageRequest(0, Integer.MAX_VALUE);

First page for results is 0. Since you're returning all records, they are all at first page (0).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download