我发送了以下请求:
GET http://127.0.0.1:8080/ajax/rest/teamService/list HTTP/1.1
Host: 127.0.0.1:8080
Connection: keep-alive
Accept: application/json, text/javascript, */*; q=0.01
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31
Referer: http://127.0.0.1:8080/do/controlpanel
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: JSESSIONID=MMezuISPiL9aOEvxmoOKbUWI.undefined
我的spring服务xml将/ ajax映射到控制器。该映射应该响应:
@RequestMapping(value = "/rest/*")
public @ResponseBody JSONResponse team(@ModelAttribute("cpSession") ControlPanelSession sess, Model model, HttpServletRequest request) {
...
}
同一控制器中的其他映射answer / ajax调用就好了。例如:
@RequestMapping(value = "/isFNameOK", method = RequestMethod.GET)
@ResponseBody
public String isFNameOK(@ModelAttribute("cpSession") ControlPanelSession sess, Model model, HttpServletRequest request, @RequestParam("fName") String fName) {
...
}
但显然不是,因为我得到了:
No mapping found for HTTP request with URI [/ajax/rest/teamService/list]
有什么想法吗?
答案 0 :(得分:3)
/ rest / *将与/rest/teamService
匹配,但不会与/rest/teamService/list
匹配。
您可以使用/ rest / **来匹配/ rest路径下的所有内容。但是,您可能更喜欢使用:
@RequestMapping(value = "/rest/{service}/{action}")
public @ResponseBody JSONResponse team(@PathVariable String service, @PathVariable String action, ...) {
哪个匹配您的网址,并在方法正文中提供通配件以供进一步检查。