Loading

Springboot统一异常处理

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 控制器全局异常处理
 *
 * @author pj.w@qq.com
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    @ResponseBody
    @ExceptionHandler(Exception.class)
    public Object globalExceptionHandler(Exception e) {
        e.printStackTrace();
        return e.getMessage();
    }

    @ResponseBody
    @ExceptionHandler(MyE.class)
    public Object globalExceptionHandler(MyE e) {
        e.printStackTrace();
        return e.getMessage();
    }
}
posted @ 2020-01-29 14:05  mahoshojo  阅读(124)  评论(0编辑  收藏  举报