How to set check order for JSR303 bean validation

后端 未结 3 1870
情书的邮戳
情书的邮戳 2021-01-01 03:57

I use the JSR303 Bean Validation to check the form input.

@NotBlank
@Size(min = 4, max = 30)
private String name;

@NotBlank
@Size(max = 100)
@Email
private          


        
3条回答
  •  难免孤独
    2021-01-01 04:22

    The order of validation related annotations / constraints cannot be specified at time of writing this answer. I've submitted order related issue to Hibernate Validator team a time ago, the issue was was accepted and probably will be solved in a next Bean Validation specification release - see more details here: http://beanvalidation.org/proposals/BVAL-248/ Btw, in simple cases you can avoid "order conflict" by using "non conflicting" combinations of annotations, e.g. NotNull and Size - Size will evaluate to true for null value.

提交回复
热议问题