这里本文只做到最简单的功能实现
package com.lingyang.system.util.exception;
import com.lingyang.system.util.result.Result;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* @author **文
* @Description:
* @createDate 2024/7/19 11:36
**/
@ResponseBody
@ControllerAdvice
public class MyGlobalExceptionHandler {
@ExceptionHandler(value = Exception.class)
public Result<String> handleException(HttpServletRequest h, Exception e) {
e.printStackTrace();
return Result.error(e.getMessage());
}
}