spring-framework / org.springframework.web.method.support / HandlerMethodArgumentResolver

HandlerMethodArgumentResolver

interface HandlerMethodArgumentResolver

Strategy interface for resolving method parameters into argument values in the context of a given request.

Author
Arjen Poutsma

Since
3.1

See Also
HandlerMethodReturnValueHandler

Functions

resolveArgument

abstract fun resolveArgument(parameter: MethodParameter, mavContainer: ModelAndViewContainer, webRequest: NativeWebRequest, binderFactory: WebDataBinderFactory): Any

Resolves a method parameter into an argument value from a given request. A ModelAndViewContainer provides access to the model for the request. A WebDataBinderFactory provides a way to create a WebDataBinder instance when needed for data binding and type conversion purposes.

supportsParameter

abstract fun supportsParameter(parameter: MethodParameter): Boolean

Whether the given MethodParameter is supported by this resolver.

Inheritors

AbstractNamedValueMethodArgumentResolver

abstract class AbstractNamedValueMethodArgumentResolver : HandlerMethodArgumentResolver

Abstract base class for resolving method arguments from a named value. Request parameters, request headers, and path variables are examples of named values. Each may have a name, a required flag, and a default value.

Subclasses define how to do the following:

  • Obtain named value information for a method parameter
  • Resolve names into argument values
  • Handle missing argument values when argument values are required
  • Optionally handle a resolved value

A default value string can contain ${...} placeholders and Spring Expression Language #{...} expressions. For this to work a ConfigurableBeanFactory must be supplied to the class constructor.

A WebDataBinder is created to apply type conversion to the resolved argument value if it doesn't match the method parameter type.

AbstractWebArgumentResolverAdapter

abstract class AbstractWebArgumentResolverAdapter : HandlerMethodArgumentResolver

An abstract base class adapting a WebArgumentResolver to the HandlerMethodArgumentResolver contract.

Note: This class is provided for backwards compatibility. However it is recommended to re-write a WebArgumentResolver as HandlerMethodArgumentResolver. Since #supportsParameter can only be implemented by actually resolving the value and then checking the result is not WebArgumentResolver#UNRESOLVED any exceptions raised must be absorbed and ignored since it's not clear whether the adapter doesn't support the parameter or whether it failed for an internal reason. The HandlerMethodArgumentResolver contract also provides access to model attributes and to WebDataBinderFactory (for type conversion).

ErrorsMethodArgumentResolver

open class ErrorsMethodArgumentResolver : HandlerMethodArgumentResolver

Resolves Errors method arguments.

An Errors method argument is expected to appear immediately after the model attribute in the method signature. It is resolved by expecting the last two attributes added to the model to be the model attribute and its BindingResult.

MapMethodProcessor

open class MapMethodProcessor : HandlerMethodArgumentResolver, HandlerMethodReturnValueHandler

Resolves Map method arguments and handles Map return values.

A Map return value can be interpreted in more than one ways depending on the presence of annotations like @ModelAttribute or @ResponseBody. Therefore this handler should be configured after the handlers that support these annotations.

MatrixVariableMapMethodArgumentResolver

open class MatrixVariableMapMethodArgumentResolver : HandlerMethodArgumentResolver

Resolves arguments of type Map annotated with where

ModelAttributeMethodProcessor

open class ModelAttributeMethodProcessor : HandlerMethodArgumentResolver, HandlerMethodReturnValueHandler

Resolve @ModelAttribute annotated method arguments and handle return values from @ModelAttribute annotated methods.

Model attributes are obtained from the model or created with a default constructor (and then added to the model). Once created the attribute is populated via data binding to Servlet request parameters. Validation may be applied if the argument is annotated with @javax.validation.Valid. or Spring's own @org.springframework.validation.annotation.Validated.

When this handler is created with annotationNotRequired=true any non-simple type argument and return value is regarded as a model attribute with or without the presence of an @ModelAttribute.

ModelMethodProcessor

open class ModelMethodProcessor : HandlerMethodArgumentResolver, HandlerMethodReturnValueHandler

Resolves Model arguments and handles Model return values.

A Model return type has a set purpose. Therefore this handler should be configured ahead of handlers that support any return value type annotated with @ModelAttribute or @ResponseBody to ensure they don't take over.

PathVariableMapMethodArgumentResolver

open class PathVariableMapMethodArgumentResolver : HandlerMethodArgumentResolver

Resolves Map method arguments annotated with an @PathVariable where the annotation does not specify a path variable name. The created Map contains all URI template name/value pairs.

RedirectAttributesMethodArgumentResolver

open class RedirectAttributesMethodArgumentResolver : HandlerMethodArgumentResolver

Resolves method arguments of type RedirectAttributes.

This resolver must be listed ahead of org.springframework.web.method.annotation.ModelMethodProcessor and org.springframework.web.method.annotation.MapMethodProcessor, which support Map and Model arguments both of which are "super" types of RedirectAttributes and would also attempt to resolve a RedirectAttributes argument.

RequestHeaderMapMethodArgumentResolver

open class RequestHeaderMapMethodArgumentResolver : HandlerMethodArgumentResolver

Resolves Map method arguments annotated with @RequestHeader. For individual header values annotated with @RequestHeader see RequestHeaderMethodArgumentResolver instead.

The created Map contains all request header name/value pairs. The method parameter type may be a MultiValueMap to receive all values for a header, not only the first one.

RequestParamMapMethodArgumentResolver

open class RequestParamMapMethodArgumentResolver : HandlerMethodArgumentResolver

Resolves Map method arguments annotated with an @RequestParam where the annotation does not specify a request parameter name. See RequestParamMethodArgumentResolver for resolving Map method arguments with a request parameter name.

The created Map contains all request parameter name/value pairs. If the method parameter type is MultiValueMap instead, the created map contains all request parameters and all there values for cases where request parameters have multiple values.

ServletRequestMethodArgumentResolver

open class ServletRequestMethodArgumentResolver : HandlerMethodArgumentResolver

Resolves request-related method argument values of the following types:

  • WebRequest
  • ServletRequest
  • MultipartRequest
  • HttpSession
  • PushBuilder (as of Spring 5.0 on Servlet 4.0)
  • Principal
  • InputStream
  • Reader
  • HttpMethod (as of Spring 4.0)
  • Locale
  • TimeZone (as of Spring 4.0)
  • java.time.ZoneId (as of Spring 4.0 and Java 8)

ServletResponseMethodArgumentResolver

open class ServletResponseMethodArgumentResolver : HandlerMethodArgumentResolver

Resolves response-related method argument values of types:

  • ServletResponse
  • OutputStream
  • Writer

SessionStatusMethodArgumentResolver

open class SessionStatusMethodArgumentResolver : HandlerMethodArgumentResolver

Resolves a SessionStatus argument by obtaining it from the ModelAndViewContainer.

UriComponentsBuilderMethodArgumentResolver

open class UriComponentsBuilderMethodArgumentResolver : HandlerMethodArgumentResolver

Resolvers argument values of type UriComponentsBuilder.

The returned instance is initialized via ServletUriComponentsBuilder#fromServletMapping(HttpServletRequest).