首先,为什么你需要使用模型驱动的接口,在你的情况下,你可以简单地使用动作支持在你的视图上渲染 bean。你必须这样:
1:首先,您应该在要更新之前填充视图,我的意思是,当您被重定向到要更新数据库的页面时,您应该在视图中填充数据。
2:您可以通过对操作进行一些更改来实现此目的:
在你的行动中
public void setProfileBean(UserProfile profileBean) {
this.profileBean = profileBean;
}
public UserProfile getProfile() {
return profileBean;
}
**i assume this is your target method**
public string execute()
{
UserProfile user=new UserProfile();
user.setProfileBean("whatever you want to set");
......
......
return SUCCESS;
}
就是这样,这样做 struts2 将自动填充视图上的数据,确保您已定义如下属性:
<s:property value="UserProfile .xyz">