import entity.Result; import entity.StatusCode; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseBody; /** * 交给spring容器管理 标识是一个异常处理器 * * @author 三国的包子 * @version 1.0 * @package com.changgou.goods.controller * * @since 1.0 */ @ControllerAdvice public class BaseExceptionHandler { //方法当被@requestMapingg注解修饰的方法 有 异常发生的时候 被调用 // Exception.class 当 发生了 Exeption 异常以及它的子类的异常都被捕获到处理. @ExceptionHandler(value= Exception.class) @ResponseBody public Result handlerException(Exception e){ e.printStackTrace(); return new Result(false, StatusCode.ERROR,e.getMessage()); } }
全局异常处理类BaseExceptionHandler
最新推荐文章于 2023-07-27 09:45:57 发布