com.houkunlin.system.common.aop.IPV4AddressValidConstraintValidator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of system-common-aop-starter Show documentation
Show all versions of system-common-aop-starter Show documentation
常用的 AOP 注解功能。
Commonly used AOP annotation features.
The newest version!
package com.houkunlin.system.common.aop;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
/**
* IP地址解析验证。忽略空字符串数据。
*
* @author HouKunLin
* @see IpUtil#ip2long(String)
*/
public class IPV4AddressValidConstraintValidator implements ConstraintValidator {
@Override
public boolean isValid(final Object value, final ConstraintValidatorContext context) {
if (value == null) {
return true;
}
if (value instanceof String ip) {
if (ip.isBlank()) {
return true;
}
return IpUtil.ip2long(ip) >= 0;
}
return IpUtil.ip2long(value.toString()) >= 0;
}
@Override
public void initialize(final IPV4AddressValid constraintAnnotation) {
}
}