kindly elaborate it?
+2
A:
@ModelAttribute refers to a property of the Model object (the M in MVC ;) so let's say we have a form with a form backing object which is called "Person" Then you can have Spring MVC supply this Object to a Controller method by using the @ModelAttribute annotation:
public String processForm(@ModelAttribute("person") Person person){
person.getStuff();
}
check here for an example
on the other hand the Annotation is used to define Objects which should be part of a Model. So if you want to have an Object "person" to be referenced in the Model you can use the following method:
@ModelAttribute("person")
public Person getPerson(){
return new Person();
}
with this method you will have Access to the person Object in your View, because the the person object gets automagically added to the Models which hold the objects used in Views
hope this helped..
smeg4brains
2010-08-06 11:56:28
that really helped.. thanx all
MohdAdnan
2010-09-20 11:34:00