You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
706 B
24 lines
706 B
package com.ruoyi.common.utils.bean; |
|
|
|
import java.util.Set; |
|
import javax.validation.ConstraintViolation; |
|
import javax.validation.ConstraintViolationException; |
|
import javax.validation.Validator; |
|
|
|
/** |
|
* bean对象属性验证 |
|
* |
|
* @author ruoyi |
|
*/ |
|
public class BeanValidators |
|
{ |
|
public static void validateWithException(Validator validator, Object object, Class<?>... groups) |
|
throws ConstraintViolationException |
|
{ |
|
Set<ConstraintViolation<Object>> constraintViolations = validator.validate(object, groups); |
|
if (!constraintViolations.isEmpty()) |
|
{ |
|
throw new ConstraintViolationException(constraintViolations); |
|
} |
|
} |
|
}
|
|
|