我正在努力定義我的jsr 303驗證規則,即爲我的容器bean重新定義默認組。對列表和列表元素進行Jsr 303驗證
@GroupSequence({Container.class, Container.Step2.class})
public class Container {
@NotNull
private String def;
@Valid
@Size(min = 20, groups = Container.Step2.class)
private List<Element> elems = new LinkedList<Element>();
public interface Step2{}
}
public class Element{
@NotNull
private String foo;
}
我想有容器豆的大小驗證,當且僅當:
- DEF屬性有效
- 的任何元素豆沒有驗證錯誤withing elems的收集
即使內部元素bean存在驗證錯誤,也會觸發大小驗證程序。
如果我從容器類刪除@GroupSequence(跳過重新定義默認組容器),並定義自己的GroupSequence爲:
@GroupSequence({Default.class, Container2.Step2.class})
public interface AllValid{}
然後
與AllValid組生效:如預期
Container c = new Container();
...
validator.validate(c, Container2.AllValid.class);
一切正常。 任何想法?