首页 > 代码库 > SpringMVC的拦截器与Controller里return "redirect:XXX"的问题

SpringMVC的拦截器与Controller里return "redirect:XXX"的问题

自己在网上也找到遇到同样问题的两篇文章:

http://q.cnblogs.com/q/62314/

http://stackoverflow.com/questions/9786028/spring-mvc-interceptor-addobject/9786096#9786096

下面分享一下个人对这个问题的解决办法,同时也请有更好解决方法的高手不吝指教!

首先是controller层:(这是点击页面“注册”按钮,表单提交的action)

// 保存到数据库
	@RequestMapping(value = http://www.mamicode.com/"doRegister", method = RequestMethod.POST)>展现用户主页
    @RequestMapping(value = http://www.mamicode.com/"{username}", method = RequestMethod.GET)> 其次是拦截器:(加入一些全局配置,如基本的站点信息) 
@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object arg2,
			ModelAndView modelAndView) throws Exception {

		final Map<String, Object> model = modelAndView.getModel();

		if (!(modelAndView.getView() instanceof RedirectView)) {
			model.put("param1", "value1");
			model.put("param2", "value2");
			model.put("param3", "value3");
		} else {
			//进行其它操作
		}

	}



关键点是org.springframework.web.servlet.view.RedirectView。

SpringMVC的拦截器与Controller里return "redirect:XXX"的问题