zoukankan      html  css  js  c++  java
  • 3-9 公共业务异常统一处理

    放在utils里面

    先引入日志

    SpringBoot提供的ControllerAdvice

    我们要捕获的是CommonServiceException.class

    打印异常的信息。这里serviceExceptionHandler方法上面两个注解,一定不要漏了。@ExceptionHandler(CommserviceException.class) 和@ResponseBody



    以上基础建设就算是完成了。

    package com.mooc.meetingfilm.utils.exception;
    
    import com.mooc.meetingfilm.utils.vo.BaseResponseVO;
    import lombok.extern.slf4j.Slf4j;
    import org.springframework.web.bind.annotation.ControllerAdvice;
    import org.springframework.web.bind.annotation.ExceptionHandler;
    
    import javax.servlet.http.HttpServletRequest;
    
    /**
     * 公共异常处理类
     */
    @Slf4j
    @ControllerAdvice
    public class BaseExceptionHandler {
    
        @ExceptionHandler(CommonServiceException.class)
      @ReponseBody
    public BaseResponseVO serviceExceptionHandelr(HttpServletRequest request,CommonServiceException e){ log.error("CommonSerException, Code{}, message",e.getCode(),e.getMessage()); return BaseResponseVO.serviceException(e); } }

    结束




     

  • 相关阅读:
    Eclipse下Tomcat插件的安装
    支付宝接口资料解读
    文件转换器服务推荐
    接吻的学问
    Web小工具推荐
    两个优秀的免费字体资源
    每年考证时间
    Visual Studio 2008 简体中文版和MSDN下载
    生活小经验
    UIScrollView and lazy loading
  • 原文地址:https://www.cnblogs.com/wangjunwei/p/12688343.html
Copyright © 2011-2022 走看看