tlias管理系统-全局异常处理器功能实现

This commit is contained in:
2025-10-27 14:12:00 +08:00
parent 31d5f542ea
commit 54d17225d4

View File

@@ -0,0 +1,19 @@
package com.inmind.exception;
import com.inmind.pojo.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@RestControllerAdvice//配置为全局异常处理器
public class GlobalException {
/*
定义一个全局异常处理的方法只要出现异常就会被ex方法处理
*/
@ExceptionHandler(Exception.class)
public Result ex(Exception e){
e.printStackTrace();
//日志框架logback把异常信息保存到日志文件
return Result.error("对不起,服务器报错,请联系管理员");
}
}