如何使用Spring RequestMapping区分域

Nil*_*ils 5 java dns url spring

我正在尝试使用不同的方法,具体取决于从哪个域发送请求。

例如

@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 {
}
Run Code Online (Sandbox Code Playgroud)

这两个域路由到相同的服务器和Web应用程序,但是我想根据需求来自哪个URL,在controller类中返回不同的modelAndView。

有任何想法吗?

干杯。

min*_*das 4

难道你不能有一个简单的handleRequest方法来检查HTTP引用头并采取相应的行动 - 分叉到不同的方法等?