每当我在文本框中输入空字符串并试图保存它时, 我就会有此错误 :
Failed to convert property value of type java.lang.String to
required type double for property customerAcctSetting.maxAllowableAmount;
nested exception is java.lang.IllegalArgumentException: Cannot convert value of
type [java.lang.String] to required type [double] for
property maxAllowableAmount:
PropertyEditor [bp.ar.util.NumberFormatUtil$CustomerDoubleEditor] returned
inappropriate value
但当我输入一个无效的数字格式, 如“ ddd” 时, 我有一个错误 :
Failed to convert property value of type java.lang.String to required
type double for property customerAcctSetting.maxAllowableAmount;
nested exception is java.lang.NumberFormatException: For input string: "ddd"
我控制器里有这个夹子
@InitBinder
public void initBinder(WebDataBinder binder) {
NumberFormatUtil.registerDoubleFormat(binder);
}
我有一个等级 numberFormatUtil.java
, 执行静态函数 registerDoubleFormat(binder)
:
public static void registerDoubleFormat (WebDataBinder binder) {
binder.registerCustomEditor(Double.TYPE, new CustomerDoubleEditor());
}
private static class CustomerDoubleEditor extends PropertyEditorSupport{
public String getAsText() {
Double d = (Double) getValue();
return d.toString();
}
public void setAsText(String str) {
if( str == "" || str == null )
setValue(0);
else
setValue(Double.parseDouble(str));
}
}
Im use Spring 3.0.1. Im use Spring 3.0.1. Im very new to Java 和诸如春天等其他相关技术。 请帮助。 提前感谢 。