Hibernate Validation註解列表

來源:互聯網
上載者:User

標籤:

下面是主要的驗證註解及說明:

註解

適用的資料類型

說明

@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格式

Hibernate Validation註解列表

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.