我有一个带有许多其他嵌套对象和对象列表的 Java 对象。当请求从客户端到达时,我看到 Object 仅填充到几个级别。是否有任何配置设置这是 Struts 2?这是我的例子。
class MyActionClass extends ActionSupport {
private Abc abc;
public Abc getAbc() {
return abc;
}
public void setAbc(Abc abc) {
this.abc = abc;
}
public String populate() {
MyService myService = new MyService();
abc = myService.getMyAbc();
return SUCCESS;
}
public String update() {
MyService myService = new MyService();
myService.updateAbc(abc);
return SUCCESS;
}
}
class Abc {
private List<Def> defList;
private Ghi ghi;
public void setDefList(List<Def> defList) {
this.defList = defList;
}
public List<Def> getDefList(){
return defList;
}
public void setGhi(Ghi ghi) {
this.ghi = ghi;
}
public Ghi getGhi() {
return ghi;
}
}
class Def {
private String name;
private long id;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
}
class Ghi {
private List<Def> defList;
private String ghiName;
public void setDefList(List<Def> defList) {
this.defList = defList;
}
public List<Def> getDefList() {
return defList;
}
public void setGhiName(String ghiName) {
this.ghiName = ghiName;
}
public String getGhiName() {
return ghiName;
}
}
当我调用该populate
方法并发送到 jsp 时,迭代对所有元素都很好。但是,当我尝试更新时,即提交表单时,update()
会调用该方法,但实例变量 abc 并未完全填充。
我已经看到了通过的 url,一切似乎都很好。让我告诉你会发生什么。url 将类似于(为了便于理解,这里用换行符分割),
&abc.defList[0].name=alex
&abc.defList[0].id=1
&abc.defList[1].name=bobby
&abc.defList[1].id=2
&abc.ghi.ghiName=GHINAME
&abc.ghi.defList[0].name=Jack
&abc.ghi.defList[0].id=1
&abc.ghi.defList[1].name=Jill
&abc.ghi.defList[1].id=2
在这种情况下,defList
内部abc
和内部ghi.ghiName
都abc
没有问题。但是defList
ofabc.ghi
没有填充。这是 Struts 2 的常见行为吗?有什么方法可以覆盖它吗?