views:

261

answers:

1

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
that really helped.. thanx all
MohdAdnan