在save方法中 添加异常
作为springmvc 的异常处理器
@ControllerAdvice
@RestControllerAdvice
包含有@ControllerAdvice
和@ResponseBody
package com.itheima.controller.util;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
//作为springmvc 的异常处理器
//@ControllerAdvice
@RestControllerAdvice
public class ProjectExceptionAdvice {
//拦截所有的异常信息 ex 就是拦截到的异常对象
@ExceptionHandler
public R doException( Exception ex){
// 记录日志
// 通知运维
// 通知开发
ex.printStackTrace();
return new R(false,"服务器故障");
}
}
添加失败的信息改为