This commit is contained in:
lx
2026-01-15 10:53:54 +08:00
commit 9b2543f7f7
80 changed files with 2995 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
package com.backend.webbackend.Exception;
import com.backend.webbackend.Vo.ResultVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
@Slf4j
@ControllerAdvice//主要作用:统一异常处理,全局数据绑定:通过InitBinder为所有控制器添加预定义的数据绑定规则,全局模型属性,通过ModelAttribute注解为所有控制器的模型添加公共属性
public class GlobalExceptionHandler {
@ExceptionHandler(Exception.class)//异常捕获,当与ControllerAdvice注解一起使用时,可以捕获所有控制器抛出的异常,并统一处理
@ResponseBody//返回数据
public ResultVo error(Exception e){
log.error("Unhandled exception", e);
return ResultVo.Error("",e.getMessage());
}
}