springmvc统一异常处理器

/**
*  springmvc异常处理器,当发生异常的时候,会捕获到,然后跳转到异常页面
*/
public class SaaSException implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
        ModelAndView mv = new ModelAndView();
        mv.addObject("errorMsg","系统出现异常:"+ex.getMessage()+",请联系系统管理员");
        mv.setViewName("error");
        return mv;
    }
}
上一篇:一文弄懂SpringMVC


下一篇:Spring MVC