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

Ruwanka Madhushan picture Ruwanka Madhushan · Feb 5, 2017 · Viewed 39.9k times · Source

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

chekmare picture chekmare · Dec 25, 2018

The more correct way is to use Pageable.unpaged()

Pageable wholePage = Pageable.unpaged();
return customerRepository.findAll(wholePage);