I am new to spring mvc and have seen examples where folks use @ModelAttribute("form") Person person
in method parameter and some who just do (Person person)
. what is the difference.
Thanks in advance
I am new to spring mvc and have seen examples where folks use @ModelAttribute("form") Person person
in method parameter and some who just do (Person person)
. what is the difference.
Thanks in advance
@ModelAttribute
allows you to specify the name of the model attribute. When parameter doesn't have this annotation, a decapitalized class name is used as an attribute name, i.e. Person p
-> "person".
If you don't specify @ModelAttribute
in this situation, then Spring will infer the presence of one. In this case, it would infer @ModelAttribute("person")
. The argument is the name of the model.
If you don't want the default name, or if you just want to be explicit about saying that the Person
parameter is a model attribute, then you should specify @ModelAttribute
, with or without the explicit name.