Spring uses implementations of an interface called HandlerMethodArgumentResolver
for resolving arguments to pass to handler methods, ie. methods annotated with @RequestMapping
.
One of these is a ModelAttributeMethodProcessor
. Its javadoc states
Resolves method arguments annotated with
@ModelAttribute
and handles return values from methods annotated with@ModelAttribute
.Model attributes are obtained from the model or if not found possibly created with a default constructor if it is available. Once created, the attributed is populated with request data via data binding and also validation may be applied if the argument is annotated with
@javax.validation.Valid
.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
.
Spring registers two objects of this type. One to handle parameters annotated with @ModelAttribute
and one to handle ones without.
Further reading: