2011-06-15 78 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