springBoot2.x 全局捕获异常

/**
 * 全局捕获异常
 */
@ControllerAdvice(basePackages = "com.liangjian.controller")//扫包范围
public class GlobalExceptionHandler {

    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public Map<String, Object> exceptionHandler() {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("errorCode", "500");
        map.put("errorMsg", "系統错误!");
        return map;
    }

}

 

posted @ 2019-07-07 09:05  CsatleChen  阅读(565)  评论(0编辑  收藏  举报