gpt4 book ai didi

java - Oval - Java 的对象验证框架

转载 作者:行者123 更新时间:2023-11-30 04:29:13 25 4
gpt4 key购买 nike

@ValidateWithMethod(methodName = "isValidPostalCode", parameterType = String.class)
private String _postalCode;

private boolean isValidPostalCode(String _postalCode) {
boolean status = false;
if (this.getTypeEnum() == 2) {
if ((this.getPostal_code() == null)|| (this.getPostal_code() == "")) {
status = true;
}
}
return status;
}

我也在使用 Oval 1.7 开发 Android 应用程序。我正在尝试使用 @ValidateWithMethod 来验证实体类(属性验证),但它不起作用,我猜它无法识别该方法,所有其他注释如 @MaxLength (value = 12) 正在工作。请帮助...

最佳答案

尝试:

private boolean isValidPostalCode(String postalCode) {

if (postalCode == null || postalCode.isEmpty()) {

编辑:您还应该将 ignoreIfNull = false 添加到注释中。见http://oval.sourceforge.net/api/net/sf/oval/constraint/ValidateWithMethod.html#ignoreIfNull ()

关于java - Oval - Java 的对象验证框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8006034/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com