Class SortHandlerMethodArgumentResolverSupport

java.lang.Object
org.springframework.data.web.SortHandlerMethodArgumentResolverSupport
Direct Known Subclasses:
ReactiveSortHandlerMethodArgumentResolver, SortHandlerMethodArgumentResolver

public abstract class SortHandlerMethodArgumentResolverSupport extends Object
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 Details

    • SortHandlerMethodArgumentResolverSupport

      public SortHandlerMethodArgumentResolverSupport()
  • Method Details

    • setSortParameter

      public void setSortParameter(String sortParameter)
      propertyDel Configure the request parameter to lookup sort information from. Defaults to sort.
      Parameters:
      sortParameter - must not be null or empty.
    • setPropertyDelimiter

      public void setPropertyDelimiter(String propertyDelimiter)
      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

      public String getPropertyDelimiter()
      Returns:
      the configured delimiter used to separate property references and the direction to be sorted by
    • setQualifierDelimiter

      public void setQualifierDelimiter(String qualifierDelimiter)
      Configures the delimiter used to separate the qualifier from the sort parameter. Defaults to _, so a qualified sort property would look like qualifier_sort.
      Parameters:
      qualifierDelimiter - the qualifier delimiter to be used or null to reset to the default.
    • setFallbackSort

      public 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.

      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.

      Parameters:
      fallbackSort - the Sort to be used as general fallback.
    • getDefaultFromAnnotationOrFallback

      protected Sort getDefaultFromAnnotationOrFallback(MethodParameter parameter)
      Reads the default Sort to be used from the given MethodParameter. Rejects the parameter if both an SortDefault.SortDefaults and SortDefault annotation is found as we cannot build a reliable Sort instance then (property ordering).
      Parameters:
      parameter - will never be null.
      Returns:
      the default Sort instance derived from the parameter annotations or the configured fallback-sort setFallbackSort(Sort).
    • getSortParameter

      protected String getSortParameter(@Nullable MethodParameter parameter)
      Returns the sort parameter to be looked up from the request. Potentially applies qualifiers to it.
      Parameters:
      parameter - can be null.
      Returns:
    • foldIntoExpressions

      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.
      Parameters:
      sort - must not be null.
      Returns:
    • legacyFoldExpressions

      protected List<String> legacyFoldExpressions(Sort sort)
      Folds the given Sort instance into two expressions. The first being the property list, the second being the direction.
      Parameters:
      sort - must not be null.
      Returns:
      Throws:
      IllegalArgumentException - if a Sort with multiple Sort.Directions has been handed in.