@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 @jakarta.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.
| Modifier and Type | Field and Description |
|---|---|
| private final boolean | |
| protected final Log |
| Access | Constructor and Description |
|---|---|
| public | ModelAttributeMethodProcessor(boolean
if "true", non-simple method arguments and
return values are considered model attributes with or without a
annotationNotRequired)@ModelAttribute annotationClass constructor. |
| Modifier and Type | Method and Description |
|---|---|
| protected void | bindRequestParameters(WebDataBinder
the data binder instance to use for the binding binder, NativeWebRequest the current request request)Extension point to bind the request to the target object via setters/fields. |
| protected void | constructAttribute(WebDataBinder
the data binder instance to use for the binding binder, NativeWebRequest the current request request)Extension point to create the attribute, binding the request to constructor args. |
| protected Object | Returns: the created model attribute, ornullthe name of the attribute (never attributeName, MethodParameter null)the method parameter declaration parameter, WebDataBinderFactory for creating WebDataBinder instance binderFactory, NativeWebRequest the current request request)Extension point to create the model attribute if not found in the model, with subsequent parameter binding through bean properties (unless suppressed). |
| public void | handleReturnValue(Object
the value returned from the handler method returnValue, MethodParameter the type of the return value. This type must have
previously been passed to returnType, ModelAndViewContainer supportsReturnType which must
have returned true.the ModelAndViewContainer for the current request mavContainer, NativeWebRequest the current request webRequest)Implements org. Add non-null return values to the |
| protected boolean | isBindExceptionRequired(WebDataBinder
the data binder used to perform data binding binder, MethodParameter the method parameter declaration parameter)Whether to raise a fatal bind exception on validation errors. |
| protected boolean | isBindExceptionRequired(MethodParameter
the method parameter declaration parameter)Whether to raise a fatal bind exception on validation errors. |
| public final Object | resolveArgument(MethodParameter
the method parameter to resolve. This parameter must
have previously been passed to parameter, ModelAndViewContainer supportsParameter which must
have returned true.the ModelAndViewContainer for the current request mavContainer, NativeWebRequest the current request webRequest, WebDataBinderFactory a factory for creating binderFactory)WebDataBinder instancesImplements org. Resolve the argument from the model or if not found instantiate it with its default if it is available. |
| public boolean | supportsParameter(MethodParameter
the method parameter to check parameter)Implements org. Returns |
| public boolean | supportsReturnType(MethodParameter
the method return type to check returnType)Implements org. Return |
| protected void | validateIfApplicable(WebDataBinder
the DataBinder to be used binder, MethodParameter the method parameter declaration parameter)Validate the model attribute if applicable. |
| private static Object |
| annotationNotRequired | back to summary |
|---|---|
| private final boolean annotationNotRequired | |
| logger | back to summary |
|---|---|
| protected final Log logger | |
| ModelAttributeMethodProcessor | back to summary |
|---|---|
| public ModelAttributeMethodProcessor(boolean annotationNotRequired) Class constructor.
| |
| bindRequestParameters | back to summary |
|---|---|
| protected void bindRequestParameters(WebDataBinder binder, NativeWebRequest request) Extension point to bind the request to the target object via setters/fields.
| |
| constructAttribute | back to summary |
|---|---|
| protected void constructAttribute(WebDataBinder binder, NativeWebRequest request) Extension point to create the attribute, binding the request to constructor args.
| |
| createAttribute | back to summary |
|---|---|
| protected Object createAttribute(String attributeName, MethodParameter parameter, WebDataBinderFactory binderFactory, NativeWebRequest request) throws Exception Extension point to create the model attribute if not found in the model, with subsequent parameter binding through bean properties (unless suppressed). By default, as of 6.1 this method returns
| |
| isBindExceptionRequired | back to summary |
|---|---|
| protected boolean isBindExceptionRequired(WebDataBinder binder, MethodParameter parameter) Whether to raise a fatal bind exception on validation errors. The default implementation delegates to
| |
| isBindExceptionRequired | back to summary |
|---|---|
| protected boolean isBindExceptionRequired(MethodParameter parameter) Whether to raise a fatal bind exception on validation errors.
| |
| resolveArgument | back to summary |
|---|---|
| public final Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception Implements org. 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
| |
| supportsParameter | back to summary |
|---|---|
| public boolean supportsParameter(MethodParameter parameter) Implements org. Returns
| |
| supportsReturnType | back to summary |
|---|---|
| public boolean supportsReturnType(MethodParameter returnType) Implements org. Return
| |
| validateIfApplicable | back to summary |
|---|---|
| protected void validateIfApplicable(WebDataBinder binder, MethodParameter parameter) Validate the model attribute if applicable. The default implementation checks for
| |
| wrapAsOptionalIfNecessary | back to summary |
|---|---|
private static Object wrapAsOptionalIfNecessary(MethodParameter parameter, Object target)
| |