[monitor] 自定义校验器注解@HostValid
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.usthe.manager.pojo.entity;
|
||||
|
||||
import com.usthe.manager.support.valid.HostValid;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -61,6 +62,7 @@ public class Monitor {
|
||||
*/
|
||||
@ApiModelProperty(value = "监控的对端host", example = "192.167.25.11", accessMode = READ_WRITE, position = 4)
|
||||
@Length(max = 100)
|
||||
@HostValid
|
||||
private String host;
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.usthe.manager.support.valid;
|
||||
|
||||
import com.usthe.common.util.IpDomainUtil;
|
||||
|
||||
import javax.validation.ConstraintValidator;
|
||||
import javax.validation.ConstraintValidatorContext;
|
||||
|
||||
/**
|
||||
* host注解数据自定义校验器
|
||||
* @author tomsun28
|
||||
* @date 2021/11/17 19:44
|
||||
*/
|
||||
public class HostParamValidator implements ConstraintValidator<HostValid, String> {
|
||||
|
||||
@Override
|
||||
public boolean isValid(String value, ConstraintValidatorContext context) {
|
||||
// 判断value是否满足ipv4 ipv5 域名 格式
|
||||
return IpDomainUtil.validateIpDomain(value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.usthe.manager.support.valid;
|
||||
|
||||
import javax.validation.Constraint;
|
||||
import javax.validation.Payload;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static java.lang.annotation.ElementType.FIELD;
|
||||
import static java.lang.annotation.ElementType.PARAMETER;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
/**
|
||||
* host注解数据自定义校验器注解
|
||||
* @author tomsun28
|
||||
* @date 2021/11/17 19:42
|
||||
*/
|
||||
@Target({ FIELD, PARAMETER })
|
||||
@Retention(RUNTIME)
|
||||
@Documented
|
||||
@Constraint(validatedBy = HostParamValidator.class)
|
||||
public @interface HostValid {
|
||||
|
||||
String message() default "Host value is invalid,must ipv4, ipv6 or domain";
|
||||
|
||||
Class<?>[] groups() default {};
|
||||
|
||||
Class<? extends Payload>[] payload() default {};
|
||||
}
|
||||
@@ -11,8 +11,6 @@ configmap:
|
||||
type: 1
|
||||
- key: password
|
||||
type: 2
|
||||
- key: param1
|
||||
type: 1
|
||||
# 指标组列表
|
||||
metrics:
|
||||
# 第一个监控指标组 cpu
|
||||
|
||||
@@ -29,5 +29,6 @@ param:
|
||||
- field: ssl
|
||||
name: 启动SSL
|
||||
type: radio
|
||||
required: false
|
||||
# 当type为radio单选框,checkbox复选框时,option表示可选项值列表
|
||||
option: Yes,No
|
||||
Reference in New Issue
Block a user