|
|
@@ -1,6 +1,6 @@
|
|
|
package cn.iocoder.yudao.framework.dict.validation;
|
|
|
|
|
|
-import cn.iocoder.yudao.framework.common.util.string.StrUtils;
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.iocoder.yudao.framework.dict.core.DictFrameworkUtils;
|
|
|
import jakarta.validation.ConstraintValidator;
|
|
|
import jakarta.validation.ConstraintValidatorContext;
|
|
|
@@ -19,19 +19,22 @@ public class InDictCollectionValidator implements ConstraintValidator<InDict, Co
|
|
|
|
|
|
@Override
|
|
|
public boolean isValid(Collection<?> list, ConstraintValidatorContext context) {
|
|
|
- if (list == null) {
|
|
|
+ // 为空时,默认不校验,即认为通过
|
|
|
+ if (CollUtil.isEmpty(list)) {
|
|
|
return true;
|
|
|
}
|
|
|
+ // 校验全部通过
|
|
|
List<String> dbValues = DictFrameworkUtils.getDictDataValueList(dictType);
|
|
|
boolean match = list.stream().allMatch(v -> dbValues.stream()
|
|
|
.anyMatch(dbValue -> dbValue.equalsIgnoreCase(v.toString())));
|
|
|
if (match) {
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
// 校验不通过,自定义提示语句
|
|
|
context.disableDefaultConstraintViolation(); // 禁用默认的 message 的值
|
|
|
context.buildConstraintViolationWithTemplate(
|
|
|
- context.getDefaultConstraintMessageTemplate().replaceAll("\\{value}",dbValues.toString())
|
|
|
+ context.getDefaultConstraintMessageTemplate().replaceAll("\\{value}", dbValues.toString())
|
|
|
).addConstraintViolation(); // 重新添加错误提示语句
|
|
|
return false;
|
|
|
}
|