Module spring.data.commons
Package org.springframework.data.web
Class SortHandlerMethodArgumentResolverSupport
java.lang.Object
org.springframework.data.web.SortHandlerMethodArgumentResolverSupport
- Direct Known Subclasses:
ReactiveSortHandlerMethodArgumentResolver,SortHandlerMethodArgumentResolver
Base class providing methods for handler method argument resolvers to create
Sort instances from request
parameters or SortDefault annotations.- Since:
- 2.2
- Author:
- Mark Paluch, Vedran Pavic, Johannes Englmeier
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfoldIntoExpressions(Sort sort) Folds the givenSortinstance into aListof sort expressions, accumulatingSort.Orderinstances of the same direction into a single expression if they are in order.protected SortReads the defaultSortto be used from the givenMethodParameter.protected StringgetSortParameter(MethodParameter parameter) Returns the sort parameter to be looked up from the request.legacyFoldExpressions(Sort sort) Folds the givenSortinstance into two expressions.voidsetFallbackSort(Sort fallbackSort) Configures theSortto be used as fallback in case noSortDefaultorSortDefault.SortDefaults(the latter only supported in legacy mode) can be found at the method parameter to be resolved.voidsetPropertyDelimiter(String propertyDelimiter) Configures the delimiter used to separate property references and the direction to be sorted by.voidsetQualifierDelimiter(String qualifierDelimiter) Configures the delimiter used to separate the qualifier from the sort parameter.voidsetSortParameter(String sortParameter) propertyDel Configure the request parameter to lookup sort information from.
-
Constructor Details
-
SortHandlerMethodArgumentResolverSupport
public SortHandlerMethodArgumentResolverSupport()
-
-
Method Details
-
setSortParameter
propertyDel Configure the request parameter to lookup sort information from. Defaults tosort.- Parameters:
sortParameter- must not be null or empty.
-
setPropertyDelimiter
Configures the delimiter used to separate property references and the direction to be sorted by. Defaults to , which means sort values look like this:firstname,lastname,asc.- Parameters:
propertyDelimiter- must not be null or empty.
-
getPropertyDelimiter
- Returns:
- the configured delimiter used to separate property references and the direction to be sorted by
-
setQualifierDelimiter
Configures the delimiter used to separate the qualifier from the sort parameter. Defaults to_, so a qualified sort property would look likequalifier_sort.- Parameters:
qualifierDelimiter- the qualifier delimiter to be used or null to reset to the default.
-
setFallbackSort
Configures theSortto be used as fallback in case noSortDefaultorSortDefault.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
Sortdata can be found in the request.- Parameters:
fallbackSort- theSortto be used as general fallback.
-
getDefaultFromAnnotationOrFallback
Reads the defaultSortto be used from the givenMethodParameter. Rejects the parameter if both anSortDefault.SortDefaultsandSortDefaultannotation is found as we cannot build a reliableSortinstance then (property ordering).- Parameters:
parameter- will never be null.- Returns:
- the default
Sortinstance derived from the parameter annotations or the configured fallback-sortsetFallbackSort(Sort).
-
getSortParameter
Returns the sort parameter to be looked up from the request. Potentially applies qualifiers to it.- Parameters:
parameter- can be null.- Returns:
-
foldIntoExpressions
Folds the givenSortinstance into aListof sort expressions, accumulatingSort.Orderinstances of the same direction into a single expression if they are in order.- Parameters:
sort- must not be null.- Returns:
-
legacyFoldExpressions
Folds the givenSortinstance into two expressions. The first being the property list, the second being the direction.- Parameters:
sort- must not be null.- Returns:
- Throws:
IllegalArgumentException- if aSortwith multipleSort.Directions has been handed in.
-