简体   繁体   中英

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 .

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

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

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

PageRequest.of(0, Integer.MAX_VALUE);

The first page for results is 0. Since you're returning all records, they are all on this page.

If you pass null for Pageable, Spring will ignore it and brings all data.

Pageable p = null;
return customerRepository.findAll(p);

As of spirng-data-commons@2.1.0 correct syntax is PageRequest.of(0, Integer.MAX_VALUE) . You can look here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM