admin
2024-05-11 c860ca1d4ceaa4065ac5f0257d7b4181880acedd
提交 | 用户 | 时间
e57a89 1 package com.jcdm.common.utils.bean;
2
3 import java.util.Set;
4 import javax.validation.ConstraintViolation;
5 import javax.validation.ConstraintViolationException;
6 import javax.validation.Validator;
7
8 /**
9  * bean对象属性验证
10  * 
11  * @author jc
12  */
13 public class BeanValidators
14 {
15     public static void validateWithException(Validator validator, Object object, Class<?>... groups)
16             throws ConstraintViolationException
17     {
18         Set<ConstraintViolation<Object>> constraintViolations = validator.validate(object, groups);
19         if (!constraintViolations.isEmpty())
20         {
21             throw new ConstraintViolationException(constraintViolations);
22         }
23     }
24 }