A request for a single well-specified page of query results.
A query method of a repository may have a parameter of type
PageRequest if its return type indicates that it may return
multiple entities, that is, if its return type is an array type,
List, Stream, Page, or CursoredPage.
The parameter of type PageRequest must occur after the method
parameters representing regular parameters of the query itself. For
example:
@OrderBy("age")
@OrderBy("ssn")
Person[] findByAgeBetween(int minAge, int maxAge, PageRequest pageRequest);
This method might be called as follows:
var page = people.findByAgeBetween(35, 59,
PageRequest.ofSize(100));
var results = page.content();
...
while (page.hasNext()) {
page = people.findByAgeBetween(35, 59,
page.nextPageRequest().withoutTotal());
results = page.content();
...
}
A repository method may not be declared with:
| Modifier and Type | Class and Description |
|---|---|
| public static interface | PageRequest.
A cursor that is formed from a key, relative to which a next or previous page can be requested. |
| public static enum | PageRequest.
The type of pagination: offset-based or cursor-based, which includes a direction. |
| Modifier and Type | Method and Description |
|---|---|
| public static PageRequest | Returns: a new instance ofPageRequest with forward cursor-based pagination.
This method never returns null.The page number. pageNumber, int The number of query results in a full page. maxPageSize, boolean Indicates whether to retrieve the
total
number of elements available across all pages. requestTotal)Requests cursor-based pagination in the forward direction, starting after the specified key. |
| public PageRequest | Returns: a new instance ofPageRequest with forward cursor-based pagination.
This method never returns null.cursor with key values, the order and number of which must match the
cursorOrderBy annotations, jakarta. parameters, or
OrderBy name pattern of the repository method to which
this pagination will be supplied.Requests cursor-based pagination in the forward direction, starting after the specified key. |
| public static PageRequest | Returns: a new instance ofPageRequest with cursor-based pagination
in the previous page direction.
This method never returns null.The page number. pageNumber, int The number of query results in a full page. maxPageSize, boolean Indicates whether to retrieve the
total
number of elements available across all pages. requestTotal)Requests cursor-based pagination in the previous page direction relative to the specified cursor. |
| public PageRequest | Returns: a new instance ofPageRequest with cursor-based pagination
in the previous page direction. This method never returns null.cursor with key values, the order and number of which must match the
cursorOrderBy annotations, jakarta. parameters, or
OrderBy name pattern of the repository method to which
this pagination will be supplied.Requests cursor-based pagination in the previous page direction relative to the specified key values. |
| public Optional | Returns: the cursor;Optional#empty() if using offset pagination.Returns the key values which are the starting point for cursor-based pagination. |
| public boolean | |
| public PageRequest. | |
| public static PageRequest | Returns: a new instance ofPageRequest. This method never returns null.The page number. pageNumber)Creates a new page request with the given page number and with a default size of 10. |
| public static PageRequest | Returns: a new instance ofPageRequest. This method never returns null.The page number. pageNumber, int The number of query results in a full page. maxPageSize, boolean Indicates whether to retrieve the
total
number of elements available across all pages. requestTotal)Creates a new page request without a cursor. |
| public static PageRequest | Returns: a new instance ofPageRequest. This method never returns null.The number of query results in a full page. maxPageSize)Creates a new page request for requesting pages of the specified size, starting with the first page number, which is 1. |
| public long | |
| public boolean | Returns: true if the total number of elements should
be retrieved from the database.Indicates that a query method which returns a |
| public int | |
| public PageRequest | Returns: a new instance ofPageRequest.
This method never returns null.the number of query results in a full page. maxPageSize)Creates a new page request with the same pagination information, but with the specified maximum page size. |
| public PageRequest | withoutTotal()
Returns an otherwise-equivalent page request with
|
| public PageRequest | withTotal()
Returns an otherwise-equivalent page request with
|
| afterCursor | back to summary |
|---|---|
| public static PageRequest afterCursor(PageRequest. Requests cursor-based pagination in the forward direction, starting after the specified key.
| |
| afterCursor | back to summary |
|---|---|
| public PageRequest afterCursor(PageRequest. Requests cursor-based pagination in the forward direction, starting after the specified key.
| |
| beforeCursor | back to summary |
|---|---|
| public static PageRequest beforeCursor(PageRequest. Requests cursor-based pagination in the previous page direction relative to the specified cursor.
| |
| beforeCursor | back to summary |
|---|---|
| public PageRequest beforeCursor(PageRequest. Requests cursor-based pagination in the previous page direction relative to the specified key values.
| |
| cursor | back to summary |
|---|---|
| public Optional Returns the key values which are the starting point for cursor-based pagination.
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object o) Compares with another instance to determine if both represent the same pagination information.
| |
| mode | back to summary |
|---|---|
| public PageRequest. Returns the type of pagination.
| |
| ofPage | back to summary |
|---|---|
| public static PageRequest ofPage(long pageNumber) Creates a new page request with the given page number and with a default size of 10.
| |
| ofPage | back to summary |
|---|---|
| public static PageRequest ofPage(long pageNumber, int maxPageSize, boolean requestTotal) Creates a new page request without a cursor.
| |
| ofSize | back to summary |
|---|---|
| public static PageRequest ofSize(int maxPageSize) Creates a new page request for requesting pages of the specified size, starting with the first page number, which is 1.
| |
| page | back to summary |
|---|---|
| public long page() Returns the page to be returned.
| |
| requestTotal | back to summary |
|---|---|
| public boolean requestTotal() Indicates that a query method which returns a
| |
| size | back to summary |
|---|---|
| public int size() Returns the requested size of each page
| |
| size | back to summary |
|---|---|
| public PageRequest size(int maxPageSize) Creates a new page request with the same pagination information, but with the specified maximum page size. When a page is retrieved from the database, the number of elements in the page must be equal to the maximum page size unless there is an insufficient number of elements to retrieve from the database from the start of the page.
| |
| withoutTotal | back to summary |
|---|---|
| public PageRequest withoutTotal() Returns an otherwise-equivalent page request with
| |
| withTotal | back to summary |
|---|---|
| public PageRequest withTotal() Returns an otherwise-equivalent page request with
| |
| Modifier and Type | Method and Description |
|---|---|
| public List | Returns: an unmodifiable list containing the ordered valuesAn unmodifiable list of values in the key. |
| public boolean | |
| public static PageRequest. | |
| public Object | Returns: the key value at the specified position.position (0 is first) of the key value to obtain. index)Returns the key value at the specified position. |
| public int | |
| public int | |
| public String | Returns: String representation of the cursor.String representation of the cursor, including the number of key values in the cursor but not the values themselves. |
| elements | back to summary |
|---|---|
| public List An unmodifiable list of values in the key.
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object cursor) Returns whether or not the values that make up the key of this cursor are equal to those of the supplied cursor. Both instances must also have the same cursor implementation class in order to be considered equal. | |
| forKey | back to summary |
|---|---|
| public static PageRequest. Obtain an instance of
| |
| get | back to summary |
|---|---|
| public Object get(int index) Returns the key value at the specified position.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Returns a hash code based on the key values.
| |
| size | back to summary |
|---|---|
| public int size() Returns the number of values in the key.
| |
| toString | back to summary |
|---|---|
| public String toString() String representation of the cursor, including the number of key values in the cursor but not the values themselves. | |
| Modifier and Type | Field and Description |
|---|---|
| public static final PageRequest. | CURSOR_NEXT
Indicates forward cursor-based pagination, which follows the direction of the sort criteria, using a cursor that is formed from the key of the last entity on the current page. |
| public static final PageRequest. | CURSOR_PREVIOUS
Indicates a request for a page with cursor-based pagination in the previous page direction to the sort criteria, using a cursor that is formed from the key of first entity on the current page. |
| public static final PageRequest. | OFFSET
Indicates a request for a page using offset pagination. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static PageRequest. | |
| public static PageRequest. |
| CURSOR_NEXT | back to summary |
|---|---|
| public static final PageRequest. Indicates forward cursor-based pagination, which follows the direction of the sort criteria, using a cursor that is formed from the key of the last entity on the current page. | |
| CURSOR_PREVIOUS | back to summary |
|---|---|
| public static final PageRequest. Indicates a request for a page with cursor-based pagination in the previous page direction to the sort criteria, using a cursor that is formed from the key of first entity on the current page. The order of results on each page follows the sort criteria and is not reversed. | |
| OFFSET | back to summary |
|---|---|
| public static final PageRequest. Indicates a request for a page using offset pagination. The starting position for pages is computed as an offset from the first result based on the page number and maximum page size. Offset pagination is used when a cursor is not supplied. | |
| Mode | back to summary |
|---|---|
| private Mode() | |
| valueOf | back to summary |
|---|---|
| public static PageRequest. | |
| values | back to summary |
|---|---|
| public static PageRequest. | |