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; } }