1.

What is a Model Attribute?

Answer»

The @ModelAttribute annotation is one of the most important Spring - MVC annotations.

The @ModelAttribute is an annotation that links a method PARAMETER or method return value to the attribute named model and then exposes it to a web view.

At the Method Level

The purpose of this method is to add one or more model attributes when the annotation is used at the method level. Such METHODS support the same types of arguments as @RequestMapping, but cannot be mapped directly to requests.

@RequestMapping(value = "/addUser", method = RequestMethod.POST) public String submit(@ModelAttribute("user") User user) { // Code that uses the user OBJECT return "userView"; }

It binds the data of the FORM to a bean. The controller annotated with @RequestMapping can be annotated with @ModelAttribute by custom class argument(s). This is commonly referred to as data binding in Spring - MVC, a COMMON mechanism that saves you from individually analyzing each form field.



Discussion

No Comment Found