• SpringMVC的处理器全局异常处理类


    SpringMVC的处理器全局异常处理类

    package com.huawei.utils;
    import org.springframework.web.servlet.HandlerExceptionResolver;
    import org.springframework.web.servlet.ModelAndView;

    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    @Component
    public class MyExceptionHandler implements HandlerExceptionResolver {
        /*
         * @param httpServletRequest
         * @param httpServletResponse
         * @param o 在那个对象中出现异常
         * @param e 异常对象
         * @return
         */
        @Override
        public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
    
            if(ex instanceof UnauthorizedException) {
                return new ModelAndView("forward:/unauthorized.jsp");
            }else {
                ModelAndView mv = new ModelAndView();
                mv.setViewName("error");
                mv.addObject("errorMsg", "对不起,我错了");
                mv.addObject("ex", ex);
                return mv;
            }
        }
    }

  • 相关阅读:
    2016去哪儿编程题:乘坐公交
    lintcode:交错正负数
    lintcode:Ugly Number I
    KMP算法
    适配器模式
    迭代器模式
    命令模式
    外观模式
    工厂方法模式
    代理模式
  • 原文地址:https://www.cnblogs.com/kitor/p/10988452.html
Copyright © 2020-2023  润新知