mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-17 09:14:39 +08:00
update 枚举验证注解EnumPattern支持更多数据类型验证
原先只支持String,现在也支持Integer、Long等常用枚举value
This commit is contained in:
parent
79bd1db16f
commit
2305e1d89e
@ -14,7 +14,7 @@ import java.util.Set;
|
|||||||
* @author 秋辞未寒
|
* @author 秋辞未寒
|
||||||
* @date 2024-12-09
|
* @date 2024-12-09
|
||||||
*/
|
*/
|
||||||
public class EnumPatternValidator implements ConstraintValidator<EnumPattern, String> {
|
public class EnumPatternValidator implements ConstraintValidator<EnumPattern, Object> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 枚举允许值集合。
|
* 枚举允许值集合。
|
||||||
@ -42,18 +42,22 @@ public class EnumPatternValidator implements ConstraintValidator<EnumPattern, St
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 校验字符串是否在枚举允许值集合内。
|
* 校验输入值是否在枚举允许值集合内。
|
||||||
*
|
*
|
||||||
* @param value 待校验值
|
* @param value 待校验值
|
||||||
* @param constraintValidatorContext 校验上下文
|
* @param constraintValidatorContext 校验上下文
|
||||||
* @return true 校验通过 false 校验失败
|
* @return true 校验通过 false 校验失败
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
|
public boolean isValid(Object value, ConstraintValidatorContext constraintValidatorContext) {
|
||||||
if (StringUtils.isBlank(value)) {
|
if (value == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return values.contains(value);
|
String text = String.valueOf(value);
|
||||||
|
if (StringUtils.isBlank(text)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return values.contains(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user