通过在请求本身中传递自定义参数来解决该问题。
代码如下:
控制者
@RequestMapping(method = RequestMethod.GET, value = "/exception2")public String getException1(ModelMap model, @CRequestParam("p") String p, HttpServletRequest request) { System.out.println("Exception 2 " + p); request.setAttribute("p", p); throw new CustomGenericException("1", "2");}
异常处理程序
@ExceptionHandler(CustomGenericException.class)public ModelAndView handleCustomException(CustomGenericException ex, HttpServletRequest request) { ModelAndView model2 = new ModelAndView("error/generic_error"); model2.addObject("exception", ex); System.out.println(request.getAttribute("p")); System.out.println("CustomGenericException "); return model2;}
完整的源代码 可以在git上找到
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)