标签:ida class spring string const TE val map not
/** * 校验工具类 * @author wdmcygah * */ public class ValidationUtils { private static Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); public static <T> ValidationResult validateEntity(T obj){ ValidationResult result = new ValidationResult(); Set<ConstraintViolation<T>> set = validator.validate(obj,Default.class); if( CollectionUtils.isNotEmpty(set) ){ result.setHasErrors(true); Map<String,String> errorMsg = new HashMap<String,String>(); for(ConstraintViolation<T> cv : set){ errorMsg.put(cv.getPropertyPath().toString(), cv.getMessage()); } result.setErrorMsg(errorMsg); } return result; } public static <T> ValidationResult validateProperty(T obj,String propertyName){ ValidationResult result = new ValidationResult(); Set<ConstraintViolation<T>> set = validator.validateProperty(obj,propertyName,Default.class); if( CollectionUtils.isNotEmpty(set) ){ result.setHasErrors(true); Map<String,String> errorMsg = new HashMap<String,String>(); for(ConstraintViolation<T> cv : set){ errorMsg.put(propertyName, cv.getMessage()); } result.setErrorMsg(errorMsg); } return result; } }
hibernate validation 手动参数校验 不经过spring
标签:ida class spring string const TE val map not
原文地址:https://www.cnblogs.com/valarchie/p/9230729.html