gavinSong
gavinSong

Reputation: 315

Convert spring data page to list

I have a page of object:

Page<Audit> audits = auditRepository.findAll(new PageRequest(1, 10));

And I want to convert audits to list of object. audit.getContent() return just the single page's data. How to get everything from all pages?

Upvotes: 1

Views: 1920

Answers (1)

Darshan Mehta
Darshan Mehta

Reputation: 30819

The (whole) point of pagination is to return partial data and page through it so you don't need to:

  • Load everything into memory
  • Worry about scrolling, total number of records, sorting and number of pages

However, if you want to get everything in one go then, you can call the overloaded version of findAll method (of JPARepository) which accepts no arguments (Javadoc here). Your code would look like this:

List<Audit> audits = auditRepository.findAll();

Upvotes: 1

Related Questions