struts2 action 接受数组参数为Null的问题

时间:2022-11-24 05:21:07
 public List<FormulaDetail> formulaDetails;
public List<FormulaDetail> getFormulaDetails() {
return formulaDetails;
}
public void setFormulaDetails(List<FormulaDetail> formulaDetails) {
this.formulaDetails = formulaDetails;
}

JSP传过来的数组formulaDetails[0].count不能被struts2接收,经过查询发现是FormulaDetail类没有缺省的构造函数

public FormulaDetail() {
}

只有一个带参数的函数

/** full constructor */
public FormulaDetail(Integer formulaId, Integer goodsCategory,
Integer percent) {
this.formulaId = formulaId;
this.goodsCategory = goodsCategory;
this.percent = percent;
}

讲缺省构造函数添加之后,成功接收数组参数