@ControllerAdvice //定義為切面攔截所有 public class GlobalExceptionHandler { @ExceptionHandler(RuntimeException.class) @ResponseBody // 攔截返回是 json返回結果 public Map<String, Object> exceptionHandler() { Map<String, Object> result=new HashMap<String, Object>(); result.put("code","500"); result.put("msg","系統錯誤");
//這里可以處理 return result; } }