what purpose , usage of @modelattribute in spring mvc?
@modelattribute refers property of model object (the m in mvc ;) let's have form form backing object called "person" can have spring mvc supply object controller method using @modelattribute annotation:
public string processform(@modelattribute("person") person person){ person.getstuff(); } check here example (spring 2.5), see "using @modelattribute on method argument" (spring 3.1).
on other hand annotation used define objects should part of model. if want have person object referenced in model can use following method:
@modelattribute("person") public person getperson(){ return new person(); } this annotated method allow access person object in view, since gets automatically added models spring.
see "using @modelattribute on method" (spring 3.1).
hope helped.
Comments
Post a Comment