constroller异常统一处理类

constroller异常统一处理类

在这里插入图片描述
其中result是想要返回的处理结果,博客目的是说明@controllerAdvice的扩展结合异常类使用

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class BaseExceptionHander {

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result error(Exception e){
        e.printStackTrace();
        return new Result();
    }
}

猜你喜欢

转载自blog.csdn.net/Guesshat/article/details/112424695