What is the purpose and usage of @ModelAttribute in Spring MVC?
What is the purpose and usage of @ModelAttribute in Spring MVC?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
@ModelAttributerefers to a property of the Model object (the M in MVC 😉so let’s say we have a form with a form backing object that is called “Person”
Then you can have Spring MVC supply this object to a Controller method by using the
@ModelAttributeannotation:On the other hand the annotation is used to define objects which should be part of a Model.
So if you want to have a Person object referenced in the Model you can use the following method:
This annotated method will allow access to the Person object in your View, since it gets automatically added to the Models by Spring.
See “Using @ModelAttribute”.