What is the mean of @ModelAttribute annotation at method argument level?
Posted
by
beemaster
on Stack Overflow
See other posts from Stack Overflow
or by beemaster
Published on 2011-01-15T16:49:18Z
Indexed on
2011/01/15
16:53 UTC
Read the original article
Hit count: 137
spring-mvc
|annotations
Spring 3 reference teaches us:
When you place it on a method parameter, @ModelAttribute maps a model attribute to the specific, annotated method parameter
I don't understand this magic spell, because i sure that model object's alias (key value if using ModelMap as return type) passed to the View after executing of the request handler method. Therefore when request handler method executes the model object's name can't be mapped to the method parameter.
To solve this contradiction i went to stackoverflow and found this detailed example. The author of example said:
// The "personAttribute" model has been passed to the controller from the JSP
It seems, he is charmed by Spring reference...
To dispel the charms i deployed his sample app in my environment and cruelly cut @ModelAttribute annotation from method MainController.saveEdit. As result the application works without any changes! So i conclude: the @ModelAttribute annotation is not needed to pass web form's field values to the argument's fields. Then i stuck to the question: what is the mean of @ModelAttribute annotation? If the only mean is to set alias for model object in View, then why this way better than explicitly adding of object to ModelMap?
© Stack Overflow or respective owner