Hibernate validation annonation

本文深入探讨了Java Bean验证注解的使用方法,包括@AssertFalse、@AssertTrue、@DecimalMax、@DecimalMin、@Digits、@Email、@Future、@Length、@Max、@Min、@NotNull、@NotEmpty、@Null、@Past、@Pattern、@Range、@Size、@Valid等常用注解的详细解释与实例应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

https://docs.jboss.org/hibernate/validator/4.0.1/reference/en/html_single/

另参见

http://docs.oracle.com/javaee/7/api/javax/validation/constraints/package-summary.html


Annotation Part of Bean Validation Specification Apply on Use Hibernate Metadata impact
@AssertFalseyesfield/propertycheck that the annotated element is false.none
@AssertTrueyesfield/propertycheck that the annotated element is true.none
@DecimalMaxyesfield/property. Supported types are BigDecimal,BigIntegerString,byteshortintlongand the respective wrappers of the primitive types.The annotated element must be a number whose value must be lower or equal to the specified maximum. The parameter value is the string representation of the max value according to theBigDecimal string representation.none
@DecimalMinyesfield/property. Supported types are BigDecimal,BigIntegerString,byteshortintlongand the respective wrappers of the primitive types.The annotated element must be a number whose value must be higher or equal to the specified minimum. The parameter value is the string representation of the min value according to theBigDecimal string representation.none
@Digits(integer=, fraction=)yesfield/property. Supported types are BigDecimal,BigIntegerString,byteshortintlongand the respective wrappers of the primitive types.Check whether the property is a number having up to integerdigits and fraction fractional digits.Define column precision and scale.
@Emailnofield/property. Needs to be a string.Check whether the specified string is a valid email address.none
@Futureyesfield/property. Supported types are java.util.Dateandjava.util.Calendar.Checks whether the annotated date is in the future.none
@Length(min=, max=)nofield/property. Needs to be a string.Validate that the annotated string is between min and maxincluded.none
@Maxyesfield/property. Supported types are BigDecimal,BigIntegerString,byteshortintlongand the respective wrappers of the primitive types.Checks whether the annotated value is less than or equal to the specified maximum.Add a check constraint on the column.
@Minyesfield/property. Supported types are BigDecimal,BigIntegerString,byteshortintlongand the respective wrappers of the primitive types.Check whether the annotated value is higher than or equal to the specified minimum.Add a check constraint on the column.
@NotNullyesfield/propertyCheck that the annotated value is not null.Column(s) are not null.
@NotEmptynofield/property. Needs to be a string.Check if the string is not null nor empty.none
@Nullyesfield/propertyCheck that the annotated value is null.none
@Pastyesfield/property. Supported types are java.util.Dateandjava.util.Calendar.Checks whether the annotated date is in the past.none
@Pattern(regex=, flag=)yesfield/property. Needs to be a string.Check if the annotated string match the regular expressionregex.none
@Range(min=, max=)nofield/property. Supported types are BigDecimal,BigIntegerString,byteshortintlongand the respective wrappers of the primitive types.Check whether the annotated value lies between (inclusive) the specified minimum and maximum.none
@Size(min=, max=)yesfield/property. Supported types are StringCollection,Map and arrays.Check if the annotated element size is between min and max (inclusive).Column length will be set to max.
@Validyesfield/propertyPerform validation recursively on the associated object.none

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值