public class PageableHandlerMethodArgumentResolver extends Object implements PageableArgumentResolver
Pageable
instances into controller
methods. Request properties to be parsed can be configured. Default configuration uses request parameters beginning
with DEFAULT_PAGE_PARAMETER
DEFAULT_QUALIFIER_DELIMITER
.Constructor and Description |
---|
PageableHandlerMethodArgumentResolver()
Constructs an instance of this resolved with a default
SortHandlerMethodArgumentResolver . |
PageableHandlerMethodArgumentResolver(SortArgumentResolver sortResolver)
Constructs an instance of this resolver with the specified
SortArgumentResolver . |
PageableHandlerMethodArgumentResolver(SortHandlerMethodArgumentResolver sortResolver)
Constructs an instance of this resolver with the specified
SortHandlerMethodArgumentResolver . |
Modifier and Type | Method and Description |
---|---|
protected int |
getMaxPageSize()
Retrieves the maximum page size to be accepted.
|
protected String |
getPageParameterName()
Retrieves the parameter name to be used to find the page number in the request.
|
protected String |
getParameterNameToUse(String source,
MethodParameter parameter)
Returns the name of the request parameter to find the
Pageable information in. |
protected String |
getSizeParameterName()
Retrieves the parameter name to be used to find the page size in the request.
|
boolean |
isFallbackPageable(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.
|
Pageable |
resolveArgument(MethodParameter methodParameter,
ModelAndViewContainer mavContainer,
NativeWebRequest webRequest,
WebDataBinderFactory binderFactory)
Resolves a
Pageable method parameter into an argument value from a given request. |
void |
setFallbackPageable(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 |
setMaxPageSize(int maxPageSize)
Configures the maximum page size to be accepted.
|
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(MethodParameter parameter) |
public PageableHandlerMethodArgumentResolver()
SortHandlerMethodArgumentResolver
.public PageableHandlerMethodArgumentResolver(SortHandlerMethodArgumentResolver sortResolver)
SortHandlerMethodArgumentResolver
.sortResolver
- the sort resolver to usepublic PageableHandlerMethodArgumentResolver(@Nullable SortArgumentResolver sortResolver)
SortArgumentResolver
.sortResolver
- the sort resolver to usepublic void setFallbackPageable(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(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 boolean supportsParameter(MethodParameter parameter)
supportsParameter
in interface HandlerMethodArgumentResolver
public Pageable resolveArgument(MethodParameter methodParameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory)
PageableArgumentResolver
Pageable
method parameter into an argument value from a given request.resolveArgument
in interface PageableArgumentResolver
resolveArgument
in interface HandlerMethodArgumentResolver
methodParameter
- the method parameter to resolve. This parameter must have previously been passed to
HandlerMethodArgumentResolver.supportsParameter(org.springframework.core.MethodParameter)
which must have returned true
.mavContainer
- the ModelAndViewContainer for the current requestwebRequest
- the current requestbinderFactory
- a factory for creating WebDataBinder
instancesprotected String getParameterNameToUse(String source, @Nullable MethodParameter parameter)
Pageable
information in. Inspects the given
MethodParameter
for Qualifier
present and prefixes the given source parameter name with it.source
- the basic parameter name.parameter
- the MethodParameter
potentially qualified.Copyright © 2011–2018 Pivotal Software, Inc.. All rights reserved.