mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
1、广告管理完善;2、菜单来源类型 -> 归属类型;
This commit is contained in:
+38
@@ -0,0 +1,38 @@
|
||||
package com.cf.imes.framework.common.validation;
|
||||
|
||||
import com.cf.imes.framework.common.core.IntArrayValuable;
|
||||
import jakarta.validation.Constraint;
|
||||
import jakarta.validation.Payload;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* @author Gqr
|
||||
* @since 2025/8/28 15:08
|
||||
*/
|
||||
@Target({
|
||||
ElementType.FIELD
|
||||
})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Constraint(
|
||||
validatedBy = {InScopeValidator.class}
|
||||
)
|
||||
public @interface InScope {
|
||||
/**
|
||||
* @return 实现 EnumValuable 接口的
|
||||
*/
|
||||
Class<? extends IntArrayValuable> value();
|
||||
|
||||
String message() default "{desc}不合法";
|
||||
|
||||
String desc() default "";
|
||||
|
||||
Class<?>[] groups() default {};
|
||||
|
||||
Class<? extends Payload>[] payload() default {};
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
package com.cf.imes.framework.common.validation;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.cf.imes.framework.common.core.IntArrayValuable;
|
||||
import jakarta.validation.ConstraintValidator;
|
||||
import jakarta.validation.ConstraintValidatorContext;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author Gqr
|
||||
* @since 2025/8/28 15:11
|
||||
*/
|
||||
public class InScopeValidator implements ConstraintValidator<InScope, List<Integer>> {
|
||||
|
||||
private List<Integer> values;
|
||||
|
||||
private String desc;
|
||||
|
||||
@Override
|
||||
public void initialize(InScope annotation) {
|
||||
IntArrayValuable[] values = annotation.value().getEnumConstants();
|
||||
if (values.length == 0) {
|
||||
this.values = Collections.emptyList();
|
||||
} else {
|
||||
this.values = Arrays.stream(values[0].array()).boxed().collect(Collectors.toList());
|
||||
}
|
||||
this.desc = annotation.desc();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(List<Integer> integers, ConstraintValidatorContext constraintValidatorContext) {
|
||||
// 为空时,默认不校验,即认为通过
|
||||
if (CollUtil.isEmpty(integers)) {
|
||||
return true;
|
||||
}
|
||||
if (values.containsAll(integers)) {
|
||||
return true;
|
||||
}
|
||||
// 校验不通过,自定义提示语句(因为,注解上的 value 是枚举类,无法获得枚举类的实际值)
|
||||
constraintValidatorContext.disableDefaultConstraintViolation(); // 禁用默认的 message 的值
|
||||
constraintValidatorContext.buildConstraintViolationWithTemplate(constraintValidatorContext.getDefaultConstraintMessageTemplate()
|
||||
.replace("{desc}", desc)).addConstraintViolation(); // 重新添加错误提示语句
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user