Skip to content

Instantly share code, notes, and snippets.

@iamitshri
Created January 31, 2019 14:23
Show Gist options
  • Save iamitshri/ee58df5f6f48a2ebb0f54b8884f38c4f to your computer and use it in GitHub Desktop.
Save iamitshri/ee58df5f6f48a2ebb0f54b8884f38c4f to your computer and use it in GitHub Desktop.
Fetch data using Spring data paging
int page = 0;
Page<Entity> pages = repo.findAll(PageRequest.of(page, 1000));
while(!pages.isLast()) {
List<Entity> content = pages.getContent();
// Do your thing with the content
Pageable pageable = pages.nextPageable();
pages = submissionRepo.findAll(pageable);
log.info("page number {} size:{}, offset:{}",pageable.getPageNumber(),pageable.getPageSize(),pageable.getOffset());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment