Skip to content

Instantly share code, notes, and snippets.

@jarod-chan
Created July 17, 2012 03:19
Show Gist options
  • Save jarod-chan/3126798 to your computer and use it in GitHub Desktop.
Save jarod-chan/3126798 to your computer and use it in GitHub Desktop.
UserValidator.java
package cn.fyg.user.domain.model;
import java.util.List;
import cn.fyg.user.service.UserException;
import net.sf.oval.ConstraintViolation;
import net.sf.oval.Validator;
public class UserValidator {
public static void validate(User user) {
Validator validator = new Validator();
List<ConstraintViolation> violations = validator.validate(user);
if(violations.size()>0){
StringBuilder message=new StringBuilder();
for (ConstraintViolation constraintViolation : violations) {
message.append(constraintViolation.getMessage()+"\n");
}
throw new UserException(message.toString());
}
}
}
@jarod-chan
Copy link
Author

oval 校验代码

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment