文件模块已完成
This commit is contained in:
@ -0,0 +1,20 @@
|
||||
package com.greenorange.promotion.annotation;
|
||||
|
||||
import com.greenorange.promotion.model.enums.FileUploadBizEnum;
|
||||
import jakarta.validation.ConstraintValidator;
|
||||
import jakarta.validation.ConstraintValidatorContext;
|
||||
|
||||
// 枚举校验器
|
||||
public class FileEnumValidator implements ConstraintValidator<UserEnumValue, String> {
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize(UserEnumValue constraintAnnotation) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(String value, ConstraintValidatorContext context) {
|
||||
return FileUploadBizEnum.getEnumByValue(value) != null;
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.greenorange.promotion.annotation;
|
||||
|
||||
import jakarta.validation.Constraint;
|
||||
import jakarta.validation.Payload;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
// 自定义校验注解
|
||||
@Constraint(validatedBy = UserEnumValidator.class)
|
||||
@Target({ ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface FileEnumValue {
|
||||
String message() default "文件业务类型错误"; // 错误信息
|
||||
Class<?>[] groups() default {}; // 组别
|
||||
Class<? extends Payload>[] payload() default {}; // 负载
|
||||
Class<? extends Enum<?>> enumClass(); // 枚举类类型
|
||||
}
|
@ -7,16 +7,16 @@ import jakarta.validation.ConstraintValidatorContext;
|
||||
|
||||
|
||||
// 枚举校验器
|
||||
public class EnumValidator implements ConstraintValidator<EnumValue, String> {
|
||||
public class UserEnumValidator implements ConstraintValidator<UserEnumValue, String> {
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize(EnumValue constraintAnnotation) {
|
||||
public void initialize(UserEnumValue constraintAnnotation) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(String value, ConstraintValidatorContext context) {
|
||||
return UserRoleEnum.getEnumByValues(value) != null;
|
||||
return UserRoleEnum.getEnumByValue(value) != null;
|
||||
}
|
||||
}
|
@ -9,10 +9,10 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
// 自定义校验注解
|
||||
@Constraint(validatedBy = EnumValidator.class)
|
||||
@Constraint(validatedBy = UserEnumValidator.class)
|
||||
@Target({ ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface EnumValue {
|
||||
public @interface UserEnumValue {
|
||||
String message() default "无效的用户角色"; // 错误信息
|
||||
Class<?>[] groups() default {}; // 组别
|
||||
Class<? extends Payload>[] payload() default {}; // 负载
|
Reference in New Issue
Block a user