我必須使用javax.validation.constraints
如下驗證表單Bean在我的Spring MVC的表單bean中的下列財產:以下驗證是否表示該字段不能爲空? (@Size註釋)
public class MyForm {
@Size(min = 2, max = 50)
private String postcode;
// getter and setter for postcode.
}
我的問題是:是否@Size(min = 2)
意味着屬性不能null
因爲它總是需要大於2的長度。之所以這麼說,是因爲在同一個包中有一個約束條件,因此如果我在上面的bean中使用約束條件,那麼約束就會變得多餘。
「空值被認爲是有效的」,在http://docs.oracle.com/javaee/6/api說/javax/validation/constraints/DecimalMax.html –