我正在尝试根据发送请求的域使用不同的方法。
例如
@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 {
}
这两个域正在路由到一个相同的服务器和 webapp,但我想在 Controller 类中返回一个不同的 modelAndView,具体取决于请求来自哪个 URL。
有什么想法吗?
干杯。
最佳答案
你能不能有一个单一的handleRequest
方法,你可以在其中简单地检查 HTTP referrer header 并采取相应的行动 - fork 到不同的方法等?
关于java - 如何使用 Spring RequestMapping 区分域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6355118/