What is the purpose and usage of @ModelAttribute in Spring MVC?
This is used for data binding purposes in Spring MVC. Let you have a jsp having a form element in it e.g
on
JSP
(Spring Form method, Simple form element can also be used)
On Controller Side
@RequestMapping(value = "/test-example", method = RequestMethod.POST)
public ModelAndView testExample(@ModelAttribute("testModelAttribute") TestModel testModel, Map map,...) {
}
Now when you will submit the form the form fields values will be available to you.