[JAVA]Validator 应用

Java validator的应用

Javax
AssertFalse
AssertTrue
DecimalMax
DecimalMin
Digits
Future
Max
Min
NotNull
Null
Past
Pattern
Size

Hibernate
CompositionType
ConstraintComposition
CreditCardNumber
Email
Length
NotBlank
NotEmpty
Range
SafeHtml
ScriptAssert
URL

 

用法(在pojo定义中)

@Email(message = "邮件地址格式不正确")
		public String getEmail() {
			return email;
		}

 使用

//output the error information
Set<ConstraintViolation<Customer>> violations = validator.validate(customer);

//throw the exceptions
ValidatorUtils.validateWithException(validator, customer);
 

 

你可能感兴趣的:(Validator)