public class SortHandlerMethodArgumentResolver extends Object implements SortArgumentResolver
HandlerMethodArgumentResolver
to automatically create Sort
instances from request parameters or
SortDefault
annotations.Constructor and Description |
---|
SortHandlerMethodArgumentResolver() |
Modifier and Type | Method and Description |
---|---|
protected List<String> |
foldIntoExpressions(Sort sort)
Folds the given
Sort instance into a List of sort expressions, accumulating Sort.Order instances
of the same direction into a single expression if they are in order. |
protected String |
getSortParameter(MethodParameter parameter)
Returns the sort parameter to be looked up from the request.
|
protected List<String> |
legacyFoldExpressions(Sort sort)
Folds the given
Sort instance into two expressions. |
Sort |
resolveArgument(MethodParameter parameter,
ModelAndViewContainer mavContainer,
NativeWebRequest webRequest,
WebDataBinderFactory binderFactory)
Resolves a
Sort method parameter into an argument value from a given request. |
void |
setFallbackSort(Sort fallbackSort)
Configures the
Sort to be used as fallback in case no SortDefault or SortDefault.SortDefaults (the
latter only supported in legacy mode) can be found at the method parameter to be resolved. |
void |
setPropertyDelimiter(String propertyDelimiter)
Configures the delimiter used to separate property references and the direction to be sorted by.
|
void |
setQualifierDelimiter(String qualifierDelimiter)
Configures the delimiter used to separate the qualifier from the sort parameter.
|
void |
setSortParameter(String sortParameter)
Configure the request parameter to lookup sort information from.
|
boolean |
supportsParameter(MethodParameter parameter) |
public void setSortParameter(String sortParameter)
sort
.sortParameter
- must not be null or empty.public void setPropertyDelimiter(String propertyDelimiter)
firstname,lastname,asc
.propertyDelimiter
- must not be null or empty.public void setQualifierDelimiter(String qualifierDelimiter)
_
, so a
qualified sort property would look like qualifier_sort
.qualifierDelimiter
- the qualifier delimiter to be used or null to reset to the default.public boolean supportsParameter(MethodParameter parameter)
supportsParameter
in interface HandlerMethodArgumentResolver
public Sort resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
SortArgumentResolver
Sort
method parameter into an argument value from a given request.resolveArgument
in interface SortArgumentResolver
resolveArgument
in interface HandlerMethodArgumentResolver
parameter
- 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
instancesnull
protected String getSortParameter(MethodParameter parameter)
parameter
- will never be null.protected List<String> foldIntoExpressions(Sort sort)
Sort
instance into a List
of sort expressions, accumulating Sort.Order
instances
of the same direction into a single expression if they are in order.sort
- must not be null.protected List<String> legacyFoldExpressions(Sort sort)
Sort
instance into two expressions. The first being the property list, the second being the
direction.sort
- must not be null.IllegalArgumentException
- if a Sort
with multiple Sort.Direction
s has been handed in.public void setFallbackSort(Sort fallbackSort)
Sort
to be used as fallback in case no SortDefault
or SortDefault.SortDefaults
(the
latter only supported in legacy mode) can be found at the method parameter to be resolved.
If you set this to null, be aware that you controller methods will get null handed into them
in case no Sort
data can be found in the request.
fallbackSort
- the Sort
to be used as general fallback.Copyright © 2011–2019 Pivotal Software, Inc.. All rights reserved.