package config.code.Exception;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import config.code.utils.BaseMap;
@ControllerAdvice
public class GloablExceptionHandler {
@ResponseBody
@ExceptionHandler(Exception.class)
public Object handleException(Exception e) {
e.printStackTrace();
// 记录错误信息
String msg = e.getMessage();
if (msg == null || msg.equals("")) {
msg = "服务器出错";
}
return BaseMap.layuiMap().failed("服务器错误");
}
}
SpringBoot-全局异常
最新推荐文章于 2024-08-24 15:16:35 发布