@ModelAttribute one has the following three functions:
① bind request parameter to command object: When placed on the parameter of a function processing method, it is used to bind multiple request parameters to a command object, thus simplifying the binding
and automatically exposed to model data for use in view page presentations;
② exposing a form reference object to model data: when placed on a processor's general method (non-functional processing method), prepares the form reference to be presented for the form
object, such as the city in which you want to select when registering, and automatically add a function before you perform a functional processing method (@RequestMapping annotation)
To the model object for use when the view page is displayed;
③ Exposure @requestmapping method returns a value of model data: when placed on the return value of a function processing method, the return value of the exposed function processing method is
Model data for use when the view page is displayed.
In spring MVC, @ModelAttribute are typically used in parameter annotations of the Controller method to interpret the model entity,
But at the same time, it can be placed in the method annotations.
If @modelattribute is placed on the annotation of a method, it is represented that all methods of the controller execute this @modelattribute method before the call
One: @ModelAttribute the parameter annotations applied to the Controller method
= "Application")publicclass applicationcontroller{ public String Test1 (@ModelAttribute ("user") Usermodel user) { }}
Two: @ModelAttribute put on Method " all methods of the controller execute this @modelattribute method before calling .
= "Application")publicclass applicationcontroller{ @ModelAttribute ( "BasePath") public String basepath (httpservletrequest request) { = Request.getcontextpath (); return Basepath.endswith ("/")? Basepath.substring (0, Basepath.length ()-1): BasePath; }}
"Spring MVC"-@ModelAttribute use