I had many constraint on a single property, like this:
@NotEmpty
@Size(min = 2, max = 20)
@Pattern(regexp= "^[0-9a-z_A-Z\u4e00-\u9fa5]+$")
private String username;
but, when it works, it will check all constraints, and I just want check step by step, so how can i do? and I found a special constraint, that is @Email constraint, I do like this:
@NotEmpty
@Email
private String email;
I found it will check step by step, if the @NotEmpty constraint check failed, it will not check @Email constraint, I just found @Email have the function, I want to say, there is some especial for @Email?
It is so confused for me, and I hoped someone could help me, thanks.
Sounds like you should look into creating a custom validator.
here is a good example on how to setup a basic custom validator (go to section called Custom Validator Implementations, especially the way they do the EmployeeFormValidator): http://www.journaldev.com/2668/spring-mvc-form-validation-example-using-annotation-and-custom-validator-implementation
Creata a custom ordering in there that you want to have and then just bind it within your controller against your expected object (or call the validate function.