标签:const info void 异常 lazy imp col constrain stringbu
import javax.validation.ConstraintViolation; import org.springframework.stereotype.Service; import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; import com.dragon.common.BusinessException; import com.dragon.common.enums.BizExceptionEnum; @Service public class MyValidatorBean extends LocalValidatorFactoryBean{ public <T> void validates(T object, Class<?>... groups) { Set<ConstraintViolation<T>> result = super.validate(object, groups); StringBuilder sb = new StringBuilder(); for (ConstraintViolation<T> constraintViolation : result) { sb.append(constraintViolation.getPropertyPath()+constraintViolation.getMessage()); } if(sb.length()>1) { throw new BusinessException(BizExceptionEnum.PARAM_ERROR, sb.toString()); } } }
支持hibernate.validator下的参数校验注解,
使用时,注入,直接调用方法即可,这里抛出了我自定义的业务异常然后AOP统一处理
标签:const info void 异常 lazy imp col constrain stringbu
原文地址:https://www.cnblogs.com/Ebird/p/14873033.html