开发者

Multiple bean binding in Spring?

Suppose I want to fill two or three different beans with Spring 3 开发者_开发知识库mvc how do I do that given that <form:form> only supports one modelAttribute? And what if I have some nested beans?

Obviously I don't want to create a "BIG" bean that then I use to fill'em all...


I think the simplest solution is create a new command class and use object composition.

public class MyCommandClass implements Serializable {
   private MyFirstBean myFirstBean;
   private MySecondBean mySecondBean;
   // other beans, getters and setters, etc.
}

Your form:

<form:form modelAttribute="myCommand">
<form:input path="myFirstBean.someProperty" ... />
<form:input path="mySecondBean.someOtherProp" ... />
</form:form>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜