feat():增加系统字典效验
parent
84c9ed8b8c
commit
7d4f0f2988
|
@ -0,0 +1,41 @@
|
|||
package com.muyu.common.core.enums;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 系统是否枚举
|
||||
*/
|
||||
public enum SystemYesNo {
|
||||
YES("Y","是"),
|
||||
NO("N","否"),
|
||||
;
|
||||
|
||||
private final String code;
|
||||
|
||||
private final String info;
|
||||
|
||||
SystemYesNo(String code, String info) {
|
||||
this.code = code;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
public String getInfo() {
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 鉴别Code是否合法
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
public static boolean isCode(String code){
|
||||
return Arrays.stream(values())
|
||||
.map(SystemYesNo::getCode)
|
||||
.anyMatch(c -> c.equals(code)); //传cou
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.muyu.common.core.validation.custom;
|
||||
|
||||
import jakarta.validation.Constraint;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
/**
|
||||
* @Author:作者姓名
|
||||
* @Package:com.muyu.common.core.validation.custom
|
||||
* @Project:cloud-common-core
|
||||
* @name:IsSystemYesNo
|
||||
* @Date:2024/8/4 11:52
|
||||
*/
|
||||
|
||||
@Target({ElementType.FIELD})
|
||||
@Retention(RUNTIME)
|
||||
@Documented
|
||||
@Constraint(validatedBy = {SystemYsNoValidator.class})
|
||||
public @interface IsSystemYesNo {
|
||||
String message() default "数据字典:[系统是否] - 参数不合法";
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.muyu.common.core.validation.custom;
|
||||
|
||||
import com.muyu.common.core.enums.SystemYesNo;
|
||||
import jakarta.validation.ConstraintValidator;
|
||||
import jakarta.validation.ConstraintValidatorContext;
|
||||
|
||||
/**
|
||||
* @Author:作者姓名
|
||||
* @Package:com.muyu.common.core.validation.custom
|
||||
* @Project:cloud-common-core
|
||||
* @name:SysremYsNoValidatorw
|
||||
* @Date:2024/8/4 11:56
|
||||
*/
|
||||
public class SystemYsNoValidator implements ConstraintValidator<IsSystemYesNo,String> {
|
||||
|
||||
@Override
|
||||
public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
|
||||
return SystemYesNo.isCode(value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue