@ExceptionHandler 表示拦截异常
@ControllerAdvice public class GlobalExceptionHandler { @ExceptionHandler(RuntimeException.class) @ResponseBody public Map<String, Object> exceptionHandler() { Map<String, Object> map = new HashMap<String, Object>(); map.put("errorCode", "101"); map.put("errorMsg", "系統错误!"); return map; } }
原文:https://www.cnblogs.com/XJJD/p/10392623.html