mirror of
https://gitee.com/dromara/dax-pay
synced 2026-08-12 15:35:38 +08:00
feat 增加IP地址校验器
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package cn.bootx.platform.common.core.validation;
|
||||
|
||||
import javax.validation.Constraint;
|
||||
import javax.validation.Payload;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author xxm
|
||||
* @since 2024/6/11
|
||||
*/
|
||||
@Target({ElementType.METHOD, ElementType.FIELD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
// 标记由哪个类来执行校验逻辑,该类需要实现ConstraintValidator接口
|
||||
@Constraint(validatedBy = IpAddressValidator.class)
|
||||
public @interface IpAddress {
|
||||
|
||||
String message() default "IP地址不合法!";
|
||||
|
||||
Class<?>[] groups() default {};
|
||||
|
||||
Class<? extends Payload>[] payload() default {};
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package cn.bootx.platform.common.core.validation;
|
||||
|
||||
import cn.hutool.core.lang.Validator;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
import javax.validation.ConstraintValidator;
|
||||
import javax.validation.ConstraintValidatorContext;
|
||||
|
||||
/**
|
||||
* ip地址校验器
|
||||
* @author xxm
|
||||
* @since 2024/6/11
|
||||
*/
|
||||
public class IpAddressValidator implements ConstraintValidator<IpAddress, String> {
|
||||
|
||||
/**
|
||||
* 校验是否为IP地址。成功返回true,失败返回false
|
||||
*/
|
||||
@Override
|
||||
public boolean isValid(String str, ConstraintValidatorContext constraintValidatorContext) {
|
||||
if (StrUtil.isNotBlank(str)){
|
||||
return Validator.isIpv4(str) || Validator.isIpv6(str);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@
|
||||
<!-- 二方库版本 -->
|
||||
<bootx-platform.version>1.3.6.2</bootx-platform.version>
|
||||
<!-- 三方库 -->
|
||||
<hutool.version>5.8.24</hutool.version>
|
||||
<hutool.version>5.8.27</hutool.version>
|
||||
<oshi.version>6.4.4</oshi.version>
|
||||
<jackson.version>2.12.3</jackson.version>
|
||||
<lang3.version>3.11</lang3.version>
|
||||
|
||||
Reference in New Issue
Block a user