About the encapsulation of @ RequestBody default exception information

public JsonResult add(@RequestBody(required = false) User user){
    if(user == null){
        //  RequestBody ;
        // ;
    }
}

use @ ControllerAdvice for uniform exception handling


Spring provides its own parameter verification mechanism
validation class

public class UserValidator implements Validator {
    @Override
    public boolean supports(Class<?> aClass) {
        return aClass.equals(User.class);
    }

    @Override
    public void validate(Object o, Errors errors) {
        if (o == null) {
            errors.rejectValue("", null, "");
        }
    }
}

UserController

public class UserController {
    /**
     *  @Valid
     */
    @InitBinder
    public void initBinder(WebDataBinder binder) {
        // 
        binder.setValidator(new UserValidator());
    }
    
    public JsonResult add(@Valid @RequestBody User user, Errors errors) {
        if (errors.hasErrors()) {
            //
        }
        //balabala
    }
}

just search for the specific usage

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-1e37d0c-4446b.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-1e37d0c-4446b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?