Interface PageRequest
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:
- 
Nested Class SummaryNested ClassesModifier and TypeInterfaceDescriptionstatic interfaceA cursor that is formed from a key, relative to which a next or previous page can be requested.static enumThe type of pagination: offset-based or cursor-based, which includes a direction.
- 
Method SummaryModifier and TypeMethodDescriptionafterCursor(PageRequest.Cursor cursor) Requests cursor-based pagination in the forward direction, starting after the specified key.static PageRequestafterCursor(PageRequest.Cursor cursor, long pageNumber, int maxPageSize, boolean requestTotal) Requests cursor-based pagination in the forward direction, starting after the specified key.beforeCursor(PageRequest.Cursor cursor) Requests cursor-based pagination in the previous page direction relative to the specified key values.static PageRequestbeforeCursor(PageRequest.Cursor cursor, long pageNumber, int maxPageSize, boolean requestTotal) Requests cursor-based pagination in the previous page direction relative to the specified cursor.cursor()Returns the key values which are the starting point for cursor-based pagination.booleanCompares with another instance to determine if both represent the same pagination information.mode()Returns the type of pagination.static PageRequestofPage(long pageNumber) Creates a new page request with the given page number and with a default size of 10.static PageRequestofPage(long pageNumber, int maxPageSize, boolean requestTotal) Creates a new page request without a cursor.static PageRequestofSize(int maxPageSize) Creates a new page request for requesting pages of the specified size, starting with the first page number, which is 1.longpage()Returns the page to be returned.booleanIndicates that a query method which returns aPageshould retrieve the total number of elements available across all pages.intsize()Returns the requested size of each pagesize(int maxPageSize) Creates a new page request with the same pagination information, but with the specified maximum page size.Returns an otherwise-equivalent page request withrequestTotal()set tofalse, so that totals will not be retrieved from the database.Returns an otherwise-equivalent page request withrequestTotal()set tofalse, so that totals will be retrieved from the database.
- 
Method Details- 
ofPageCreates a new page request with the given page number and with a default size of 10.- Parameters:
- pageNumber- The page number.
- Returns:
- a new instance of PageRequest. This method never returnsnull.
- Throws:
- IllegalArgumentException- when the page number is negative or zero.
 
- 
ofPageCreates a new page request without a cursor.- Parameters:
- pageNumber- The page number.
- maxPageSize- The number of query results in a full page.
- requestTotal- Indicates whether to retrieve the total number of elements available across all pages.
- Returns:
- a new instance of PageRequest. This method never returnsnull.
- Throws:
- IllegalArgumentException- when the page number is negative or zero.
 
- 
ofSizeCreates a new page request for requesting pages of the specified size, starting with the first page number, which is 1.- Parameters:
- maxPageSize- The number of query results in a full page.
- Returns:
- a new instance of PageRequest. This method never returnsnull.
- Throws:
- IllegalArgumentException- when maximum page size is negative or zero.
 
- 
afterCursorstatic PageRequest afterCursor(PageRequest.Cursor cursor, long pageNumber, int maxPageSize, boolean requestTotal) Requests cursor-based pagination in the forward direction, starting after the specified key. - Parameters:
- cursor- cursor with key values, the order and number of which must match the- OrderByannotations or- OrderByname pattern and the- Orderand- Sortparameters of the repository method to which this page request will be supplied.
- pageNumber- The page number.
- maxPageSize- The number of query results in a full page.
- requestTotal- Indicates whether to retrieve the total number of elements available across all pages.
- Returns:
- a new instance of PageRequestwith forward cursor-based pagination. This method never returnsnull.
- Throws:
- IllegalArgumentException- if the cursor is null or has no values.
 
- 
beforeCursorstatic PageRequest beforeCursor(PageRequest.Cursor cursor, long pageNumber, int maxPageSize, boolean requestTotal) Requests cursor-based pagination in the previous page direction relative to the specified cursor. - Parameters:
- cursor- cursor with key values, the order and number of which must match the- OrderByannotations or- OrderByname pattern and the- Orderand- Sortparameters of the repository method to which this page request will be supplied.
- pageNumber- The page number.
- maxPageSize- The number of query results in a full page.
- requestTotal- Indicates whether to retrieve the total number of elements available across all pages.
- Returns:
- a new instance of PageRequestwith cursor-based pagination in the previous page direction. This method never returnsnull.
- Throws:
- IllegalArgumentException- if the cursor is null or has no values.
 
- 
afterCursorRequests cursor-based pagination in the forward direction, starting after the specified key. - Parameters:
- cursor- cursor with key values, the order and number of which must match the- OrderByannotations,- Sortparameters, or- OrderByname pattern of the repository method to which this pagination will be supplied.
- Returns:
- a new instance of PageRequestwith forward cursor-based pagination. This method never returnsnull.
- Throws:
- IllegalArgumentException- if no key values are provided.
 
- 
beforeCursorRequests cursor-based pagination in the previous page direction relative to the specified key values. - Parameters:
- cursor- cursor with key values, the order and number of which must match the- OrderByannotations,- Sortparameters, or- OrderByname pattern of the repository method to which this pagination will be supplied.
- Returns:
- a new instance of PageRequestwith cursor-based pagination in the previous page direction. This method never returnsnull.
- Throws:
- IllegalArgumentException- if no key values are provided.
 
- 
equalsCompares with another instance to determine if both represent the same pagination information.
- 
cursorOptional<PageRequest.Cursor> cursor()Returns the key values which are the starting point for cursor-based pagination.- Returns:
- the cursor; Optional.empty()if using offset pagination.
 
- 
modePageRequest.Mode mode()Returns the type of pagination.- Returns:
- the type of pagination.
 
- 
pagelong page()Returns the page to be returned.- Returns:
- the page to be returned.
 
- 
sizeint size()Returns the requested size of each page- Returns:
- the requested size of each page
 
- 
requestTotalboolean requestTotal()Indicates that a query method which returns aPageshould retrieve the total number of elements available across all pages. This behavior is enabled by default. To obtain a page request with total retrieval disabled, callwithoutTotal().- Returns:
- trueif the total number of elements should be retrieved from the database.
 
- 
sizeCreates 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. - Parameters:
- maxPageSize- the number of query results in a full page.
- Returns:
- a new instance of PageRequest. This method never returnsnull.
 
- 
withoutTotalPageRequest withoutTotal()Returns an otherwise-equivalent page request withrequestTotal()set tofalse, so that totals will not be retrieved from the database. Note that when totals are not retrieved by a repository method with return typePage, the operationsPage.totalElements()andPage.totalPages()throw anIllegalStateExceptionwhen called.- Returns:
- a page request with requestTotal()set tofalse.
 
- 
withTotalPageRequest withTotal()Returns an otherwise-equivalent page request withrequestTotal()set tofalse, so that totals will be retrieved from the database.- Returns:
- a page request with requestTotal()set totrue.
 
 
-