The difference between using and using @modelAttribute in a method parameter

I am new to spring mvc and have seen examples in which people use @ModelAttribute("form") Person personthe method parameter, and some only (Person person). what is the difference.

Thanks in advance

+3
source share
2 answers

@ModelAttributeallows you to specify the name of the model attribute. When a parameter does not have this annotation, a decapitalized class name is used as the attribute name, i.e. Person p→ "person".

+2
source

If you do not specify @ModelAttributein this situation, then Spring will cause the presence of one. In this case, it will output @ModelAttribute("person"). The argument is the name of the model.

, Person , @ModelAttribute .

+3

Source: https://habr.com/ru/post/1760088/


All Articles