假设我想用 Spring 3 mvc 填充两个或三个不同的 bean,考虑到 <form:form>
我该怎么做?仅支持一个modelAttribute
?如果我有一些嵌套的 beans 怎么办?
显然我不想创建一个“大”bean,然后用它来填充它们......
最佳答案
我认为最简单的解决方案是创建一个新的命令类并使用对象组合。
public class MyCommandClass implements Serializable {
private MyFirstBean myFirstBean;
private MySecondBean mySecondBean;
// other beans, getters and setters, etc.
}
您的表格:
<form:form modelAttribute="myCommand">
<form:input path="myFirstBean.someProperty" ... />
<form:input path="mySecondBean.someOtherProp" ... />
</form:form>
关于spring - Spring 中的多个 bean 绑定(bind)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6747567/