我有一张表格:
public class ActionLogForm extends ActionForm {
private Long ContractId;
public Long getContractId() {
return contractId;
}
public void setContractId(Long ContractId) {
this.contractId= contractId;
}
}
在JSP中,我有:
<html:hidden property="contractId" styleId="contractId" value="" />
我道歉中的actionLogForm.getContractId()
为什么0L
?
如何将默认值更改为null?
答案 0 :(得分:2)
Struts ActionForm和DynaActionForm文档明确指出。
如果您不提供初始 属性,数字将被初始化 为0,对象为null。
我知道您使用的是Long
但是(即使在自动装箱之前),以下数据类型也是“装箱”的。
当Struts看到一个Number
对象子类型而不是它的原始类型时,它会为你自动生成它,因此你有一个默认值0
。它有自己的基元/对象类型转换实现(在BeanUtils
中)。它的原因是为了向后兼容旧的Struts 1版本(在JDK 1.4和JDK 1.3上运行)。
我希望这会有所帮助。