Oval - Java 对象验证框架
@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 (值 = 12) 正在工作。请帮忙...
@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;
}
I'm developing an Android Application with the use of Oval 1.7
as well. I'm trying to validate an Entity class (property validation), with the use of @ValidateWithMethod
, but it's not working, I guess its not recognizing the method, all other annotations like @MaxLength(value = 12)
are working. Please help...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用:
private boolean isValidPostalCode(String postalCode) {
if (postalCode == null || postalCode.isEmpty()) {
编辑: 您还应该将
ignoreIfNull = false
添加到注释中。请参阅http://oval.sourceforge.net/api/ net/sf/oval/constraint/ValidateWithMethod.html#ignoreIfNull()Try with:
private boolean isValidPostalCode(String postalCode) {
if (postalCode == null || postalCode.isEmpty()) {
EDIT: You should also add
ignoreIfNull = false
to the annotation. see http://oval.sourceforge.net/api/net/sf/oval/constraint/ValidateWithMethod.html#ignoreIfNull()