0
是否可以重寫hibernate/javax驗證的類層次結構? 或者如何通過擴展類來覆蓋參數驗證?驗證類層次結構重寫
使用@Valid
註釋並在我的類中設置了javax驗證註釋。我想有一個擴展類,其中驗證被刪除。 我發現hibernate驗證循環遍歷整個類層次結構,甚至在超類中檢查驗證。 我從Spring MVC設置的基於Json的REST API中使用它。
實施例:
public class Parent {
protected Integer numChildren;
@NotNull(message = "NumChildren has to be set.")
@Size(min 1, max 10, message = "A partent has to have at least one kid.")
public Integer getNumChildren() {
return numChildren;
}
public void setNumChildren(Integer numChilds) {
this.numChildren = numChilds;
}
}
public class Child extends Parent {
// A child doesnt have to have kids, but can, so I want to override this parameter
// and remove the validation requirement, and make it just optional.
@Override
public Integer getNumChildren() {
return super.numChildren;
}
}
此致 馬庫斯