PagingAndSortingRepository findAll Pageable

The Spring Data JPA findAll method declared in PagingAndSortingRepository interface and implemented in the SimpleJpaRepository class takes Pageable interface as an input parameter and provides multiple pagination strategies to retrieve all the records of the entity type from the underlying database.

methods declared in Pageable interface is implemented in PageRequest class.

Methods declared in Pageable interface are as below.

  • first
  • next
  • getOffset
  • previousOrFirst
  • isPaged
  • isUnpaged
  • hasPrevious
  • getPageNumber
  • getPageSize
  • getSort
  • getSortOr
  • toOptional

methods defined in in PageRequest class are.

  • of(int page, int size)
  • of(int page, int size, Sort sort)
  • of(int page, int size, Direction direction, String... properties)

Page knows total records and pages available by triggering a count query to calculate the overall number. This will be additional query and expensive, its adviced to use Slice.

follow us on