spring-framework / org.springframework.web.method.annotation / ModelAttributeMethodProcessor

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.

Author
Rossen Stoyanchev

Author
Juergen Hoeller

Author
Sebastien Deleuze

Since
3.1

Constructors

<init>

ModelAttributeMethodProcessor(annotationNotRequired: Boolean)

Class constructor.

Functions

handleReturnValue

open fun handleReturnValue(returnValue: Any, returnType: MethodParameter, mavContainer: ModelAndViewContainer, webRequest: NativeWebRequest): Unit

Add non-null return values to the ModelAndViewContainer.

resolveArgument

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

Resolve the argument from the model or if not found instantiate it with its default if it is available. The model attribute is then populated with request values via data binding and optionally validated if @java.validation.Valid is present on the argument.

supportsParameter

open fun supportsParameter(parameter: MethodParameter): Boolean

Returns true if the parameter is annotated with ModelAttribute or, if in default resolution mode, for any method parameter that is not a simple type.

supportsReturnType

open fun supportsReturnType(returnType: MethodParameter): Boolean

Return true if there is a method-level @ModelAttribute or, in default resolution mode, for any return value type that is not a simple type.

Inheritors

ServletModelAttributeMethodProcessor

open class ServletModelAttributeMethodProcessor : ModelAttributeMethodProcessor

A Servlet-specific ModelAttributeMethodProcessor that applies data binding through a WebDataBinder of type ServletRequestDataBinder.

Also adds a fall-back strategy to instantiate the model attribute from a URI template variable or from a request parameter if the name matches the model attribute name and there is an appropriate type conversion strategy.