`
erichua
  • 浏览: 510851 次
  • 性别: Icon_minigender_2
  • 来自: 远方
社区版块
存档分类
最新评论

[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);
 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics