JSR-303 类型 java 字段验证是否始终/隐式在字段验证之前运行?
如果我使用 javax.validation.Validator 来验证用约束注释的对象,它是否总是在对象之前评估字段级约束?
例如,如果我有:
@DummyClassValidation
public static class DummyClassToValidate {
private Integer myNum;
@Min(value = 50)
@Max(value = 100)
public Integer getMyNum() {
return myNum;
}
public void setMyNum(Integer myNum) {
this.myNum = myNum;
}
}
并且我验证了它,是否保证仅在 @Min
和 @Max
之后评估 @DummyClassValidation
?我知道我可以使用分组来做到这一点,但如果不需要的话我宁愿不这样做(即字段验证隐式分组以在对象验证之前进行验证)。
If I am using the javax.validation.Validator
to validate an object annotated with constraints, will it always evaluate the field level constraints before the object?
For example if I have:
@DummyClassValidation
public static class DummyClassToValidate {
private Integer myNum;
@Min(value = 50)
@Max(value = 100)
public Integer getMyNum() {
return myNum;
}
public void setMyNum(Integer myNum) {
this.myNum = myNum;
}
}
And I validate it, is it guaranteed that the @DummyClassValidation
will be evaluated only after @Min
and @Max
? I know I can do so with Groupings but I rather not if I don't have to (i.e. Field validations are implicitly grouped to validate before object validations).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据规范第 3.5 节:
简而言之,你不能依赖它,除非你想找到一个保证它的实现并坚持下去。
Per the specification, section 3.5:
In short, you can't rely on that unless you want to find an implementation that guarantees it and stick with that.