好几个项目开发中,都用到了struts2的模型驱动:
public class MyAction extends ActionSupport implements ModelDriven<TestBean>
通常TestBean都是对应数据库中到一个表,也就是 一个action对应一个pojo;
那么我现在的问题是:
当我的一个编辑页面上,需要编辑到内容涉及到两张及两张以上到表到内容的时候,例如我到编辑页面上出现了 TestBean 的属性,同时还有 OtherBean 的属性,保存的方法 update() 在上面 MyAction 中,但是该action的模型驱动只包含 TestBean,如何也将 OtherBean 的属性值也自动获取呢?
因为该action中 的 getModel() 方法只拿 TestBean
public TestBean getModel() {
if(this.testBean== null){
this.testBean= new TestBean ();
}
return testBean;
}
public class MyAction extends ActionSupport implements ModelDriven<TestBean>
通常TestBean都是对应数据库中到一个表,也就是 一个action对应一个pojo;
那么我现在的问题是:
当我的一个编辑页面上,需要编辑到内容涉及到两张及两张以上到表到内容的时候,例如我到编辑页面上出现了 TestBean 的属性,同时还有 OtherBean 的属性,保存的方法 update() 在上面 MyAction 中,但是该action的模型驱动只包含 TestBean,如何也将 OtherBean 的属性值也自动获取呢?
因为该action中 的 getModel() 方法只拿 TestBean
public TestBean getModel() {
if(this.testBean== null){
this.testBean= new TestBean ();
}
return testBean;
}
希望有人能帮我解解这些疑惑!
该贴分数不够的话,另外开个贴子给分。
if(this.testBean== null){
this.testBean= new TestBean ();
}
return testBean;
}
你不觉得这个if是多余的吗.? 这个判断modelDriven拦截器会做的.!
-------
你这样的需求, 只有是在Action中再定义otherBean的属性了! 我记得模型驱动只能有一个.!
针对两个Model分别执行Update。