2011-06-15 34 views
4

我试图根据请求发送来自哪个域使用不同的方法。如何使用Spring RequestMapping区分域名

例如

@RequestMapping(value = "/index.html", domain = "google.de", method = RequestMethod.GET) 
public ModelAndView handleDeRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { 
} 

@RequestMapping(value = "/index.html", domain = "google.com", method = RequestMethod.GET) 
public ModelAndView handleComRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { 
} 

两个域分别路由到一个,同样的,服务器和Web应用程序,但我想在这取决于从哪个URL的reqeust正在添加是在controllerclass返回不同的ModelAndView。

任何想法?

欢呼声。

回答

4

您是否可以没有单一的handleRequest方法,您只需检查HTTP引用标头并相应地执行操作 - 分叉为不同的方法等。

+0

这对我来说很简单,就像我以为会那样。谢谢 – Nils 2011-06-15 12:01:58