JSR-303 validation groups define a default group

前端 未结 2 1706
时光取名叫无心
时光取名叫无心 2020-12-31 00:50

I have a bean that has a lot of fields annotated with JSR-303 validation annotations. There is a new requirement now that one of the fields is mandatory, but only in certain

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-31 01:24

    There is a Default group in javax.validation.groups.Default, which represents the default Bean Validation group. Unless a list of groups is explicitly defined:

    • constraints belong to the Default group
    • validation applies to the Default group

    You could extends this group:

    public interface ValidatedOnCreationOnly extends Default {}
    

提交回复
热议问题