public class ScanRegisterBean implements Serializable{
@Min(value = 1)
@Max(value = Long.MAX_VALUE)
private long id;
@NotBlank(groups = {ScanRegister.class, Register.class})
@Length(min = 2, max = 20,groups = {ScanRegister.class, Register.class})
private String nick;
@NotBlank(groups = {ScanRegister.class, Register.class})
@Phone(mode = 0,groups = {ScanRegister.class, Register.class})
private String phone;
@NotBlank(groups = {ScanRegister.class, Register.class})
@Length(min = 6, max = 20,groups = {ScanRegister.class, Register.class})
private String pwd;
@NotBlank(groups = {Register.class})
private String deviceId;
public interface ScanRegister {}
public interface Register{}
}
hibernate-validator configuration is a quick failure, the configuration is as follows
@Configuration
public class HibernateConfig {
// hibernate
@Bean
public Validator validator() {
ValidatorFactory validatorFactory = Validation.byProvider(HibernateValidator.class)
.configure()
.addProperty("hibernate.validator.fail_fast", "true")
.buildValidatorFactory();
Validator validator = validatorFactory.getValidator();
return validator;
}
}
The problem with is that one field cannot be checked first and the next field can be checked when checking.
for example: when the
front end submits, and when
nick, phone, pwd is left empty, it will prompt the user that nick cannot be empty. Then, when the nick is assigned a value of ha, it is submitted again, and the length of the nick is not verified, but the phone, is directly verified to see if the phone is empty. How can hibernate continue to verify the length of the nick instead of directly verifying that the Phone is empty?