修复: org.hibernate.validator.constraints包注解, 校验信息丢失属性名称的情况

This commit is contained in:
Toint 2025-10-13 00:55:23 +08:00
parent f7584b83fc
commit 54021c8796

View File

@ -82,11 +82,8 @@ public class ValidationUtil {
final Set<ConstraintViolation<Object>> constraintViolations = validate(object, groups);
if (CollUtil.isNotEmpty(constraintViolations)) {
final ConstraintViolation<Object> constraint = constraintViolations.iterator().next();
if (StrUtil.contains(constraint.getMessageTemplate(), "jakarta.validation.constraints")) {
throw new ValidationException(constraint.getPropertyPath() + StrPool.SPACE + constraint.getMessage());
} else {
throw new ValidationException(constraint.getMessage());
}
// 属性名称和错序信息之间需要有间隔, 否则可能出现粘连的情况, 例如: namemust not be null
throw new ValidationException(constraint.getPropertyPath() + StrPool.SPACE + constraint.getMessage());
}
}