diff --git a/src/main/java/cn/iocoder/dashboard/framework/validator/custom/handler/MaxHandler.java b/src/main/java/cn/iocoder/dashboard/framework/validator/custom/handler/MaxHandler.java index 9c3571f878..83ed9c71ed 100644 --- a/src/main/java/cn/iocoder/dashboard/framework/validator/custom/handler/MaxHandler.java +++ b/src/main/java/cn/iocoder/dashboard/framework/validator/custom/handler/MaxHandler.java @@ -14,6 +14,8 @@ import java.util.Date; */ public class MaxHandler implements ValidateAnnotationHandler { + private static final String MSG = "的值必须小于{}!"; + @Override public Class getAnnotation() { return Max.class; @@ -35,13 +37,9 @@ public class MaxHandler implements ValidateAnnotationHandler { valid = true; } if (!valid) { - MessageFormatter.format(getResultMsgWhenInvalid(), value).getMessage(); + MessageFormatter.format(MSG, value).getMessage(); } return null; } - @Override - public String getResultMsgWhenInvalid() { - return "的值必须小于{}!"; - } } diff --git a/src/main/java/cn/iocoder/dashboard/framework/validator/custom/handler/MinHandler.java b/src/main/java/cn/iocoder/dashboard/framework/validator/custom/handler/MinHandler.java index 34e7d0decd..d44e5f4236 100644 --- a/src/main/java/cn/iocoder/dashboard/framework/validator/custom/handler/MinHandler.java +++ b/src/main/java/cn/iocoder/dashboard/framework/validator/custom/handler/MinHandler.java @@ -14,6 +14,8 @@ import java.util.Date; */ public class MinHandler implements ValidateAnnotationHandler { + private static final String MSG = "的值必须大于{}!"; + @Override public Class getAnnotation() { return Min.class; @@ -35,13 +37,9 @@ public class MinHandler implements ValidateAnnotationHandler { valid = true; } if (!valid) { - MessageFormatter.format(getResultMsgWhenInvalid(), value).getMessage(); + MessageFormatter.format(MSG, value).getMessage(); } return null; } - @Override - public String getResultMsgWhenInvalid() { - return "的值必须小于{}!"; - } } diff --git a/src/main/java/cn/iocoder/dashboard/framework/validator/custom/handler/NotBlankHandler.java b/src/main/java/cn/iocoder/dashboard/framework/validator/custom/handler/NotBlankHandler.java index 3e29ccf039..fb3cee5c8c 100644 --- a/src/main/java/cn/iocoder/dashboard/framework/validator/custom/handler/NotBlankHandler.java +++ b/src/main/java/cn/iocoder/dashboard/framework/validator/custom/handler/NotBlankHandler.java @@ -12,6 +12,8 @@ import javax.validation.constraints.NotBlank; */ public class NotBlankHandler implements ValidateAnnotationHandler { + private static final String MSG = "格式错误或者没有有效字符!"; + @Override public Class getAnnotation() { return NotBlank.class; @@ -20,13 +22,9 @@ public class NotBlankHandler implements ValidateAnnotationHandler { @Override public String validate(NotBlank validateAnnotation, Object fieldValue) { if(StrUtil.isBlankIfStr(fieldValue)) { - return getResultMsgWhenInvalid(); + return MSG; } return null; } - @Override - public String getResultMsgWhenInvalid() { - return "格式错误或者没有有效字符!"; - } } diff --git a/src/main/java/cn/iocoder/dashboard/framework/validator/custom/handler/NotEmptyHandler.java b/src/main/java/cn/iocoder/dashboard/framework/validator/custom/handler/NotEmptyHandler.java index bf979c6a40..e259ff6750 100644 --- a/src/main/java/cn/iocoder/dashboard/framework/validator/custom/handler/NotEmptyHandler.java +++ b/src/main/java/cn/iocoder/dashboard/framework/validator/custom/handler/NotEmptyHandler.java @@ -12,6 +12,8 @@ import javax.validation.constraints.NotEmpty; */ public class NotEmptyHandler implements ValidateAnnotationHandler { + private static final String MSG = "不能为空!"; + @Override public Class getAnnotation() { return NotEmpty.class; @@ -20,13 +22,8 @@ public class NotEmptyHandler implements ValidateAnnotationHandler { @Override public String validate(NotEmpty validateAnnotation, Object fieldValue) { if(ObjectUtil.isEmpty(fieldValue)) { - return getResultMsgWhenInvalid(); + return MSG; } return null; } - - @Override - public String getResultMsgWhenInvalid() { - return "不能为空!!!!"; - } } diff --git a/src/main/java/cn/iocoder/dashboard/framework/validator/custom/handler/NotNullHandler.java b/src/main/java/cn/iocoder/dashboard/framework/validator/custom/handler/NotNullHandler.java index c81a99f9ad..c0d9c6afd2 100644 --- a/src/main/java/cn/iocoder/dashboard/framework/validator/custom/handler/NotNullHandler.java +++ b/src/main/java/cn/iocoder/dashboard/framework/validator/custom/handler/NotNullHandler.java @@ -13,6 +13,7 @@ import javax.validation.constraints.NotNull; */ public class NotNullHandler implements ValidateAnnotationHandler { + private static final String MSG = "必传!"; @Override public Class getAnnotation() { @@ -22,13 +23,8 @@ public class NotNullHandler implements ValidateAnnotationHandler { @Override public String validate(NotNull validateAnnotation, Object fieldValue) { if (ObjectUtil.isNull(fieldValue)) { - return getResultMsgWhenInvalid(); + return MSG; } return null; } - - @Override - public String getResultMsgWhenInvalid() { - return "必传!"; - } } diff --git a/src/main/java/cn/iocoder/dashboard/framework/validator/custom/handler/ValidateAnnotationHandler.java b/src/main/java/cn/iocoder/dashboard/framework/validator/custom/handler/ValidateAnnotationHandler.java index aba5875884..d5f43ec942 100644 --- a/src/main/java/cn/iocoder/dashboard/framework/validator/custom/handler/ValidateAnnotationHandler.java +++ b/src/main/java/cn/iocoder/dashboard/framework/validator/custom/handler/ValidateAnnotationHandler.java @@ -57,9 +57,5 @@ public interface ValidateAnnotationHandler { */ String validate(T validateAnnotation, Object fieldValue); - /** - * @return 消息模板 - */ - String getResultMsgWhenInvalid(); } diff --git a/src/main/java/cn/iocoder/dashboard/framework/validator/custom/handler/ValidateHandlerHelper.java b/src/main/java/cn/iocoder/dashboard/framework/validator/custom/handler/ValidateHandlerHelper.java index 45f7bf898e..1d4393ab6f 100644 --- a/src/main/java/cn/iocoder/dashboard/framework/validator/custom/handler/ValidateHandlerHelper.java +++ b/src/main/java/cn/iocoder/dashboard/framework/validator/custom/handler/ValidateHandlerHelper.java @@ -112,7 +112,7 @@ public class ValidateHandlerHelper { } else { fieldComment = field.getName(); } - String msg = fieldComment + handlerOptional.get().getResultMsgWhenInvalid(); + String msg = fieldComment + validate; CustomConstraintDescriptor customConstraintDescriptor = new CustomConstraintDescriptor<>(field.getAnnotation(handlerOptional.get().getAnnotation())); return CustomConstraintViolation.of(rootBean, msg, propertyPath, fieldValue, customConstraintDescriptor);