Package org.springframework.data.web
Class PageableHandlerMethodArgumentResolverSupport
java.lang.Object
org.springframework.data.web.PageableHandlerMethodArgumentResolverSupport
- Direct Known Subclasses:
PageableHandlerMethodArgumentResolver
,ReactivePageableHandlerMethodArgumentResolver
Base class providing methods for handler method argument resolvers to create paging information from web requests and
thus allows injecting
Pageable
instances into controller methods. Request properties to be parsed can be
configured defaulting to page
for the page number and size
for the page size.
Parameters can be prefixed
to disambiguate from other parameters in the request if
necessary.
- Since:
- 2.2
- Author:
- Mark Paluch, Vedran Pavic
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected int
Retrieves the maximum page size to be accepted.protected Pageable
getPageable
(MethodParameter methodParameter, String pageString, String pageSizeString) protected String
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 thePageable
information in.protected String
Retrieves the parameter name to be used to find the page size in the request.boolean
isFallbackPageable
(Pageable pageable) Returns whether the givenPageable
is the fallback one.protected boolean
Indicates whether to expose and assume 1-based page number indexes in the request parameters.void
setFallbackPageable
(Pageable fallbackPageable) Configures thePageable
to be used as fallback in case noPageableDefault
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
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.
-
Constructor Details
-
PageableHandlerMethodArgumentResolverSupport
public PageableHandlerMethodArgumentResolverSupport()
-
-
Method Details
-
setFallbackPageable
Configures thePageable
to be used as fallback in case noPageableDefault
can be found at the method parameter to be resolved.If you set this to Pageable#unpaged(), be aware that your controller methods will get an
unpaged
instance handed into them in case noPageable
data can be found in the request.- Parameters:
fallbackPageable
- thePageable
to be used as general fallback.
-
isFallbackPageable
Returns whether the givenPageable
is the fallback one.- Parameters:
pageable
- can be null.- Returns:
-
setMaxPageSize
public void setMaxPageSize(int maxPageSize) Configures the maximum page size to be accepted. This allows to put an upper boundary of the page size to prevent potential attacks trying to issue anOutOfMemoryError
. Defaults toDEFAULT_MAX_PAGE_SIZE
.- Parameters:
maxPageSize
- the maxPageSize to set
-
getMaxPageSize
protected int getMaxPageSize()Retrieves the maximum page size to be accepted. This allows to put an upper boundary of the page size to prevent potential attacks trying to issue anOutOfMemoryError
. Defaults toDEFAULT_MAX_PAGE_SIZE
.- Returns:
- the maximum page size allowed.
-
setPageParameterName
Configures the parameter name to be used to find the page number in the request. Defaults topage
.- Parameters:
pageParameterName
- the parameter name to be used, must not be null or empty.
-
getPageParameterName
Retrieves the parameter name to be used to find the page number in the request. Defaults topage
.- Returns:
- the parameter name to be used, never null or empty.
-
setSizeParameterName
Configures the parameter name to be used to find the page size in the request. Defaults tosize
.- Parameters:
sizeParameterName
- the parameter name to be used, must not be null or empty.
-
getSizeParameterName
Retrieves the parameter name to be used to find the page size in the request. Defaults tosize
.- Returns:
- the parameter name to be used, never null or empty.
-
setPrefix
Configures a general prefix to be prepended to the page number and page size parameters. Useful to namespace the property names used in case they are clashing with ones used by your application. By default, no prefix is used.- Parameters:
prefix
- the prefix to be used or null to reset to the default.
-
setQualifierDelimiter
The delimiter to be used between the qualifier and the actual page number and size properties. Defaults to_
. So a qualifier offoo
will result in a page number parameter offoo_page
.- Parameters:
qualifierDelimiter
- the delimiter to be used or null to reset to the default.
-
setOneIndexedParameters
public void setOneIndexedParameters(boolean oneIndexedParameters) Configures whether to expose and assume 1-based page number indexes in the request parameters. Defaults to false, meaning a page number of 0 in the request equals the first page. If this is set to true, a page number of 1 in the request will be considered the first page.- Parameters:
oneIndexedParameters
- the oneIndexedParameters to set
-
isOneIndexedParameters
protected boolean isOneIndexedParameters()Indicates whether to expose and assume 1-based page number indexes in the request parameters. Defaults to false, meaning a page number of 0 in the request equals the first page. If this is set to true, a page number of 1 in the request will be considered the first page.- Returns:
- whether to assume 1-based page number indexes in the request parameters.
-
getPageable
-
getParameterNameToUse
Returns the name of the request parameter to find thePageable
information in. Inspects the givenMethodParameter
forQualifier
present and prefixes the given source parameter name with it.- Parameters:
source
- the basic parameter name.parameter
- theMethodParameter
potentially qualified.- Returns:
- the name of the request parameter.
-