Paginating query results

Paginating query results is a very common requirement for practically every application that presents some kind of data. The key component of the pagination support of Spring Data JPA is the Pageable interface that declares the following methods:

Method

Description

int getPageNumber()

Returns the number of the requested page. The page numbers are zero indexed. Thus, the number of the first page is zero.

int getPageSize()

Returns the number of elements shown on a single page. The page size must always be larger than zero.

int getOffset()

Returns the selected offset according to the given page number and page size.

Sort getSort()

Returns the sorting parameters used to sort the query results.

We can use ...

Get Spring Data now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.