public class NarrowPageableHandlerMethodArgumentResolver extends Object implements org.springframework.data.web.PageableArgumentResolver
Pageable
implementation based on additional 'offset' and
'forward' request params that relate to UnnumberedPageable
and NarrowedPageable
,
respectively. By providing different output based on request params, well known patterns
involving Pageable and PageableDefault params can continue to be leveraged in endpoint classes.
Furthermore, narrowing behavior for a request can be changed on-the-fly (see
ContextInfo.isIgnoreNarrowing()
) and a NarrowedPageable will still work correctly to
resolve a page of records through vanilla Spring repository support. This means that the more
derived Pageable types are still backwards compatible with the less enhanced fetch flows.
The default behavior is to provide the out-of-box Spring Data implementation of Pageable when the 'offset' request parameter is omitted from the request. Next, if 'offset' is included, but 'forward' is omitted, it will provide an implementation of UnnumberedPageable. Finally, should both 'offset' and 'forward' be supplied, it will provide an implementation of NarrowedPageable.
Constructor and Description |
---|
NarrowPageableHandlerMethodArgumentResolver() |
NarrowPageableHandlerMethodArgumentResolver(org.springframework.data.web.SortArgumentResolver sortResolver) |
NarrowPageableHandlerMethodArgumentResolver(org.springframework.data.web.SortHandlerMethodArgumentResolver sortResolver) |
Modifier and Type | Method and Description |
---|---|
String |
getForwardParameterName()
Retrieves the parameter name to be used to determine if this pageable request is
incrementally moving forward through the result set, or in reverse.
|
protected int |
getMaxPageSize()
Retrieves the maximum page size to be accepted.
|
String |
getOffsetParameterName()
Retrieves the parameter name to be used to determine the number of records to offset.
|
protected String |
getPageParameterName()
Retrieves the parameter name to be used to find the page number in the request.
|
protected String |
getSizeParameterName()
Retrieves the parameter name to be used to find the page size in the request.
|
boolean |
isFallbackPageable(org.springframework.data.domain.Pageable pageable)
Returns whether the given
Pageable is the fallback one. |
protected boolean |
isOneIndexedParameters()
Indicates whether to expose and assume 1-based page number indexes in the request parameters.
|
org.springframework.data.domain.Pageable |
resolveArgument(org.springframework.core.MethodParameter methodParameter,
org.springframework.web.method.support.ModelAndViewContainer mavContainer,
org.springframework.web.context.request.NativeWebRequest webRequest,
org.springframework.web.bind.support.WebDataBinderFactory binderFactory) |
void |
setFallbackPageable(org.springframework.data.domain.Pageable fallbackPageable)
Configures the
Pageable to be used as fallback in case no PageableDefault or
PageableDefault (the latter only supported in legacy mode) can be found at the method
parameter to be resolved. |
void |
setForwardParameterName(String forwardParameterName)
Sets the parameter name to be used to determine if this pageable request is incrementally
moving forward through the result set, or in reverse.
|
void |
setMaxPageSize(int maxPageSize)
Configures the maximum page size to be accepted.
|
void |
setOffsetParameterName(String offsetParameterName)
Sets the parameter name to be used to determine the number of records to offset.
|
void |
setOneIndexedParameters(boolean oneIndexedParameters)
Configures whether to expose and assume 1-based page number indexes in the request
parameters.
|
void |
setPageParameterName(String pageParameterName)
Configures the parameter name to be used to find the page number in the request.
|
void |
setPrefix(String prefix)
Configures a general prefix to be prepended to the page number and page size parameters.
|
void |
setQualifierDelimiter(String qualifierDelimiter)
The delimiter to be used between the qualifier and the actual page number and size
properties.
|
void |
setSizeParameterName(String sizeParameterName)
Configures the parameter name to be used to find the page size in the request.
|
boolean |
supportsParameter(org.springframework.core.MethodParameter parameter) |
public NarrowPageableHandlerMethodArgumentResolver()
public NarrowPageableHandlerMethodArgumentResolver(org.springframework.data.web.SortHandlerMethodArgumentResolver sortResolver)
public NarrowPageableHandlerMethodArgumentResolver(org.springframework.data.web.SortArgumentResolver sortResolver)
public boolean supportsParameter(org.springframework.core.MethodParameter parameter)
supportsParameter
in interface org.springframework.web.method.support.HandlerMethodArgumentResolver
public org.springframework.data.domain.Pageable resolveArgument(org.springframework.core.MethodParameter methodParameter, org.springframework.web.method.support.ModelAndViewContainer mavContainer, org.springframework.web.context.request.NativeWebRequest webRequest, org.springframework.web.bind.support.WebDataBinderFactory binderFactory)
resolveArgument
in interface org.springframework.data.web.PageableArgumentResolver
resolveArgument
in interface org.springframework.web.method.support.HandlerMethodArgumentResolver
public void setFallbackPageable(org.springframework.data.domain.Pageable fallbackPageable)
Pageable
to be used as fallback in case no PageableDefault
or
PageableDefault
(the latter only supported in legacy mode) can be found at the method
parameter to be resolved.
If you set this to Optional#empty(), be aware that you controller methods will get
null handed into them in case no Pageable
data can be found in the
request. Note, that doing so will require you supply bot the page and the size
parameter with the requests as there will be no default for any of the parameters available.
fallbackPageable
- the Pageable
to be used as general fallback.public boolean isFallbackPageable(org.springframework.data.domain.Pageable pageable)
Pageable
is the fallback one.pageable
- can be null.public void setMaxPageSize(int maxPageSize)
OutOfMemoryError
. Defaults
to DEFAULT_MAX_PAGE_SIZE
.maxPageSize
- the maxPageSize to setprotected int getMaxPageSize()
OutOfMemoryError
. Defaults
to DEFAULT_MAX_PAGE_SIZE
.public void setPageParameterName(String pageParameterName)
page
.pageParameterName
- the parameter name to be used, must not be null or empty.protected String getPageParameterName()
page
.public void setSizeParameterName(String sizeParameterName)
size
.sizeParameterName
- the parameter name to be used, must not be null or empty.protected String getSizeParameterName()
size
.public void setPrefix(String prefix)
prefix
- the prefix to be used or null to reset to the default.public void setQualifierDelimiter(String qualifierDelimiter)
_
. So a qualifier of foo
will result in a page number
parameter of foo_page
.qualifierDelimiter
- the delimiter to be used or null to reset to the
default.public void setOneIndexedParameters(boolean oneIndexedParameters)
oneIndexedParameters
- the oneIndexedParameters to setprotected boolean isOneIndexedParameters()
public String getForwardParameterName()
forward
. This parameter is only used when the request is targeting
NarrowedPageable
.public void setForwardParameterName(String forwardParameterName)
forward
. This
parameter is only used when the request is targeting NarrowedPageable
.forwardParameterName
- the parameter name to be usedpublic String getOffsetParameterName()
offset
. This parameter is only used when the request is targeting
UnnumberedPageable
and NarrowedPageable
.public void setOffsetParameterName(String offsetParameterName)
offset
. This parameter is only used when the request is targeting
UnnumberedPageable
and NarrowedPageable
.offsetParameterName
- the parameter name to be usedCopyright © 2021. All rights reserved.