2014-03-29 73 views
0

我在與JSR 303的驗證問題,當用戶未在框中輸入任何驗證空號場。我想驗證一個字段必須是數字和> 0。這裏是代碼在Spring MVC

@Min(value = 1) 
private float price; 

如果輸入一個號碼驗證工作正常,但如果空拋出NumberFormatException

我知道我可以改變floatFloat和使用@NotEmpty,但我不想改變,只是因爲這個簡單的驗證類型。

任何想法?

+0

看到http://stackoverflow.com/questions/14976566/spring-initbinder-bind-empty-or-null-values-of-a-float-field-as-0尋求解決方案。基本上,你必須擴展CustomNumberEditor爲和內setAsText設置值爲0,如果輸入的文本爲空。 –

回答