Spring Boot全局异常处理

@RestControllerAdvice
public class ExceptionHandler {

    @org.springframework.web.bind.annotation.ExceptionHandler(value=MissingServletRequestParameterException.class)
    public ApiRest MissingServletRequestParameterException(MissingServletRequestParameterException ex) {
        return new ApiRest().failureWithMsg("参数缺失!");
    }
}

ApiRest类是自己定义的统一返回类

原文地址:https://www.cnblogs.com/sunang/p/15718034.html