开发者

difference between using and not using @modelAttribute in method parameter

开发者 https://www.devze.com 2023-01-11 18:10 出处:网络
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.

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".

0

精彩评论

暂无评论...
验证码 换一张
取 消