difference between using and not using @modelAttribute in method parameter
I am new to spring mvc and have seen examples where folks use @ModelAttribute("form"开发者_JAVA技巧) Person person
in method parameter and some who just do (Person person)
. what is the difference.
Thanks in advance
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.
@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".
精彩评论