parent
66b996b104
commit
adb9c43c90
|
@ -47,7 +47,7 @@ public class ValidAddCapacityInfoImpl implements ConstraintValidator<ValidAddCap
|
||||||
*/
|
*/
|
||||||
private String getFieldName(ConstraintValidatorContext ctx) {
|
private String getFieldName(ConstraintValidatorContext ctx) {
|
||||||
return ((ConstraintValidatorContextImpl) ctx).getConstraintViolationCreationContexts()
|
return ((ConstraintValidatorContextImpl) ctx).getConstraintViolationCreationContexts()
|
||||||
.get(0).getPath().getLeafNode().getName();
|
.get(0).getPath().getLeafNode().getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -60,13 +60,14 @@ public class ValidAddCapacityInfoImpl implements ConstraintValidator<ValidAddCap
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isValid(AddCapacityInfo addCapacityInfo, ConstraintValidatorContext ctx) {
|
public boolean isValid(AddCapacityInfo addCapacityInfo, ConstraintValidatorContext ctx) {
|
||||||
|
int sum = 0;
|
||||||
boolean ret = true;
|
boolean ret = true;
|
||||||
|
|
||||||
if (addCapacityInfo == null || addCapacityInfo.getCapacityType() == null) {
|
if (addCapacityInfo == null || addCapacityInfo.getCapacityType() == null) {
|
||||||
// 重新设置消息
|
// 重新设置消息
|
||||||
ctx.disableDefaultConstraintViolation();
|
ctx.disableDefaultConstraintViolation();
|
||||||
ctx.buildConstraintViolationWithTemplate(this.message + " 字段 " + getFieldName(ctx) + " 不能为null")
|
ctx.buildConstraintViolationWithTemplate(this.message + " 字段 " + getFieldName(ctx) + " 不能为null")
|
||||||
.addConstraintViolation();
|
.addConstraintViolation();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -92,9 +93,14 @@ public class ValidAddCapacityInfoImpl implements ConstraintValidator<ValidAddCap
|
||||||
for (String s : addCapacityInfo.getProtectIp().split(DisposeConfigValue.SPLIT_CHAR)) {
|
for (String s : addCapacityInfo.getProtectIp().split(DisposeConfigValue.SPLIT_CHAR)) {
|
||||||
if (!Pattern.matches(ConstValue.IP_ADDR_SEGMENT_REG, s.replace(" ", ""))) {
|
if (!Pattern.matches(ConstValue.IP_ADDR_SEGMENT_REG, s.replace(" ", ""))) {
|
||||||
errMsg.add("字段 protectIp 包含非法值: " + s);
|
errMsg.add("字段 protectIp 包含非法值: " + s);
|
||||||
|
sum += 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(sum > 0){
|
||||||
|
ret = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (addCapacityInfo.getReserveNetflow() == null) {
|
if (addCapacityInfo.getReserveNetflow() == null) {
|
||||||
|
|
Loading…
Reference in New Issue