How to set check order for JSR303 bean validation

后端 未结 3 1877
情书的邮戳
情书的邮戳 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:04

    Have you considered to define two sequences. One for name and one for mail?

    @GroupSequence({NameFirst.class, NameSecond.class})
    interface AllName {
    }
    
    @GroupSequence({MailFirst.class, MailSecond.class, MailThird.class})
    interface AllMail {
    }
    

    In this case you would call the validator like this:

    validator.validate(myObject, AllName.class, AllMail.class)
    

提交回复
热议问题