|
註解 |
適用的資料類型 |
說明 |
|
@AssertFalse |
Boolean, boolean |
驗證註解的元素值是false |
|
@AssertTrue |
Boolean, boolean |
驗證註解的元素值是true |
|
@DecimalMax(value=x) |
BigDecimal, BigInteger, String, byte,short, int, long and the respective wrappers of the primitive types. Additionally supported by HV: any sub-type of Number andCharSequence. |
驗證註解的元素值小於等於@ DecimalMax指定的value值 |
|
@DecimalMin(value=x) |
BigDecimal, BigInteger, String, byte,short, int, long and the respective wrappers of the primitive types. Additionally supported by HV: any sub-type of Number andCharSequence. |
驗證註解的元素值小於等於@ DecimalMin指定的value值 |
|
@Digits(integer=整數位元, fraction=小數位元) |
BigDecimal, BigInteger, String, byte,short, int, long and the respective wrappers of the primitive types. Additionally supported by HV: any sub-type of Number andCharSequence. |
驗證註解的元素值的整數位元和小數位元上限 |
|
@Future |
java.util.Date, java.util.Calendar; Additionally supported by HV, if theJoda Time date/time API is on the class path: any implementations ofReadablePartial andReadableInstant. |
驗證註解的元素值(日期類型)比目前時間晚 |
|
@Max(value=x) |
BigDecimal, BigInteger, byte, short,int, long and the respective wrappers of the primitive types. Additionally supported by HV: any sub-type ofCharSequence (the numeric value represented by the character sequence is evaluated), any sub-type of Number. |
驗證註解的元素值小於等於@Max指定的value值 |
|
@Min(value=x) |
BigDecimal, BigInteger, byte, short,int, long and the respective wrappers of the primitive types. Additionally supported by HV: any sub-type of CharSequence (the numeric value represented by the char sequence is evaluated), any sub-type of Number. |
驗證註解的元素值大於等於@Min指定的value值 |
|
@NotNull |
Any type |
驗證註解的元素值不是null |
|
@Null |
Any type |
驗證註解的元素值是null |
|
@Past |
java.util.Date, java.util.Calendar; Additionally supported by HV, if theJoda Time date/time API is on the class path: any implementations ofReadablePartial andReadableInstant. |
驗證註解的元素值(日期類型)比目前時間早 |
|
@Pattern(regex=Regex, flag=) |
String. Additionally supported by HV: any sub-type of CharSequence. |
驗證註解的元素值與指定的Regex匹配 |
|
@Size(min=最小值, max=最大值) |
String, Collection, Map and arrays. Additionally supported by HV: any sub-type of CharSequence. |
驗證註解的元素值的在min和max(包含)指定區間之內,如字元長度、集合大小 |
|
@Valid |
Any non-primitive type(參考型別) |
驗證關聯的對象,如賬戶對象裡有一個訂單對象,指定驗證訂單對象 |
|
@NotEmpty |
CharSequence,Collection, Map and Arrays
|
驗證註解的元素值不為null且不為空白(字串長度不為0、集合大小不為0) |
|
@Range(min=最小值, max=最大值) |
CharSequence, Collection, Map and Arrays,BigDecimal, BigInteger, CharSequence, byte, short, int, long and the respective wrappers of the primitive types
|
驗證註解的元素值在最小值和最大值之間 |
|
@NotBlank |
CharSequence
|
驗證註解的元素值不為空白(不為null、去除首位空格後長度為0),不同於@NotEmpty,@NotBlank只應用於字串且在比較時會去除字串的空格 |
|
@Length(min=下限, max=上限) |
CharSequence
|
驗證註解的元素值長度在min和max區間內 |
|
@Email |
CharSequence
|
驗證註解的元素值是Email,也可以通過Regex和flag指定自訂的email格式 |