テキストボックスに空の文字列を入力して保存しようとすると、このエラーが発生します。このエラーが発生します。
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)
:
NumberFormatUtil.java
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));
}
}
私はSpring 3.0.1を使用しています。私はJavaや春などの他の関連技術に非常に慣れていません。助けてください。前もって感謝します。