读书人

[JAVA]Validator 运用

发布时间: 2012-09-19 13:43:53 作者: rapoo

[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 informationSet<ConstraintViolation<Customer>> violations = validator.validate(customer);//throw the exceptionsValidatorUtils.validateWithException(validator, customer);
?

?

读书人网 >编程

热点推荐