Annotation Interface ModelAttribute
@RequestMapping
methods.
WARNING: Data binding can lead to security issues by exposing parts of the object graph that are not meant to be accessed or modified by external clients. Therefore the design and use of data binding should be considered carefully with regard to security. For more details, please refer to the dedicated sections on data binding for Infra Web MVC and Infra WebFlux in the reference manual.
@ModelAttribute can be used to expose command objects to a web view,
using specific attribute names, by annotating corresponding parameters of an
@RequestMapping method.
@ModelAttribute can also be used to expose reference data to a web
view by annotating accessor methods in a controller class with
@RequestMapping methods. Such accessor
methods are allowed to have any arguments that
@RequestMapping methods support, returning
the model attribute value to expose.
Note however that reference data and all other model content are
not available to web views when request processing results in an
Exception since the exception could be raised at any time
making the content of the model unreliable. For this reason
@ExceptionHandler methods do not provide
access to a Model argument.
- 从以下版本开始:
- 4.0 2022/4/8 22:50
- 作者:
- Juergen Hoeller, Rossen Stoyanchev, Harry Yang
-
可选元素概要
可选元素修饰符和类型可选元素说明booleanAllows declaring data binding disabled directly on an@ModelAttributemethod parameter or on the attribute returned from an@ModelAttributemethod, both of which would prevent data binding for that attribute.The name of the model attribute to bind to.Alias forname().
-
元素详细资料
-
value
Alias forname().- 默认值:
- ""
-
name
The name of the model attribute to bind to.The default model attribute name is inferred from the declared attribute type (i.e. the method parameter type or method return type), based on the non-qualified class name: e.g. "orderAddress" for class "mypackage.OrderAddress", or "orderAddressList" for "List<mypackage.OrderAddress>".
- 默认值:
- ""
-
binding
boolean bindingAllows declaring data binding disabled directly on an@ModelAttributemethod parameter or on the attribute returned from an@ModelAttributemethod, both of which would prevent data binding for that attribute.By default this is set to
truein which case data binding applies. Set this tofalseto disable data binding.- 默认值:
- true
-