在springboot项目中加入这个全局异常处理类
import org.example.result.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(Exception.class)
public Result handleException(Exception e){
try{
}
catch(Exception exception){
e.printStackTrace();
}
// Result.fail(msg); msg可以自由的替换成你想要的输出语句
return Result.fail("操作失败");
}
}