SpringBoot + hibernate-validator validation problem

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?

Mar.19,2021

personal opinion: the cumulative check you are talking about is recommended to be done at the front end, and the incomplete fill / error should be highlighted when submitted. The back-end verification principle should be fail as soon as possible , return the error as soon as possible, instead of waiting for the second and third error, it doesn't make much sense to do this in the backend, and the performance experience is not as efficient as completing it in the front end.


"ha" takes up two bytes, and your min is 2 just passing.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e8b353-46e00.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e8b353-46e00.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?