增加系统字典校验
parent
300cea0360
commit
f9ab7fd5c9
|
@ -0,0 +1,48 @@
|
||||||
|
package com.muyu.common.core.enums;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:zhangzhihao
|
||||||
|
* @name:SystemYseNo
|
||||||
|
* @Date:2024/7/31 19:52
|
||||||
|
* 不准抄代码,添加注释,清楚每一行代码意思
|
||||||
|
*/
|
||||||
|
public enum SystemYseNo {
|
||||||
|
YES("Y","是"),
|
||||||
|
NO("N","否")
|
||||||
|
;
|
||||||
|
|
||||||
|
private final String code;
|
||||||
|
private final String info;
|
||||||
|
|
||||||
|
SystemYseNo(String code, String info) {
|
||||||
|
this.code = code;
|
||||||
|
this.info = info;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCode(){
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getInfo(){
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 鉴别Code是否合法
|
||||||
|
* @param code
|
||||||
|
* @return 如果存在code返回true,不存在则返回false
|
||||||
|
*/
|
||||||
|
public static boolean isCode(String code){
|
||||||
|
|
||||||
|
return Arrays.stream(values())
|
||||||
|
.map(SystemYseNo::getCode)
|
||||||
|
.anyMatch(s -> s.equals(code));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.muyu.common.core.validation.custom;
|
||||||
|
|
||||||
|
import jakarta.validation.Constraint;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:zhangzhihao
|
||||||
|
* @name:IsSystemYseNo
|
||||||
|
* @Date:2024/7/31 20:11
|
||||||
|
* 不准抄代码,添加注释,清楚每一行代码意思
|
||||||
|
*/
|
||||||
|
@Target({ElementType.FIELD})
|
||||||
|
@Retention(RUNTIME)
|
||||||
|
@Documented
|
||||||
|
@Constraint(validatedBy = {SystemYsNoValidator.class})
|
||||||
|
public @interface IsSystemYseNo {
|
||||||
|
|
||||||
|
String message() default "数据字典,[系统是否] - 参数不合法";
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.muyu.common.core.validation.custom;
|
||||||
|
|
||||||
|
import com.muyu.common.core.enums.SystemYseNo;
|
||||||
|
import jakarta.validation.ConstraintValidator;
|
||||||
|
import jakarta.validation.ConstraintValidatorContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:zhangzhihao
|
||||||
|
* @name:SystemYsNoValidator
|
||||||
|
* @Date:2024/7/31 20:20
|
||||||
|
* 不准抄代码,添加注释,清楚每一行代码意思
|
||||||
|
*/
|
||||||
|
public class SystemYsNoValidator implements ConstraintValidator<IsSystemYseNo,String> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
|
||||||
|
return SystemYseNo.isCode(value);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue