SpringMVC的處理器全局異常處理類


@Component
public class MyExceptionHandler implements HandlerExceptionResolver {
    @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;
        }
    }
}

 


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
  © 2014-2022 ITdaan.com 联系我们: