1

我正在发送以下请求:

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) {

...

}

同一控制器中的其他映射可以很好地应答 /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]

有任何想法吗?

4

1 回答 1

3

/rest/* 将匹配/rest/teamService,但不匹配/rest/teamService/list

您可以使用 /rest/** 来匹配 /rest 路径下的所有内容。但是,您可能更喜欢使用:

@RequestMapping(value = "/rest/{service}/{action}")
public @ResponseBody JSONResponse team(@PathVariable String service, @PathVariable String action, ...) {

这将匹配您的 URL,并在您的方法主体中提供通配符部分以供进一步检查。

于 2013-04-21T15:51:58.697 回答