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