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 |
---|---|
|
Returns the number of the requested page. The page numbers are zero indexed. Thus, the number of the first page is zero. |
|
Returns the number of elements shown on a single page. The page size must always be larger than zero. |
|
Returns the selected offset according to the given page number and page size. |
|
Returns the sorting parameters used to sort the query results. |
We can use this interface to paginate the query results with Spring Data JPA by:
Creating a new
PageRequest
object. We can use thePageRequest
class because it implements thePageable
interface.Passing the created object to a repository method as a parameter.
If...