月光代碼園

記錄、分享、交流

导航

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类是自己定义的统一返回类

posted on 2021-12-22 09:30  bangdikka  阅读(25)  评论(0编辑  收藏  举报