我有以下代码
@Controller
@RequestMapping("/xyz")
public class MyController {
@RequestMapping(method = RequestMethod.GET, value = "/abc")
@SuppressWarnings("unchecked")
@ResponseBody
public void myMethod(String pqr) {
....
....
}
....
....
我正在制作一个AJAX请求/ contextname / xyz / abc
但是上面声明的处理程序方法没有被考虑,我得到以下错误
DEBUG o.s.web.servlet.DispatcherServlet - DispatcherServlet with name
'contextname' processing GET request for
[http://mydomain:8085/contextname/xyz/abc]
00:22:32.867 [http-nio-8080-exec-1] DEBUG
o.s.w.s.m.m.a.RequestMappingHandlerMapping - Looking up handler method for
path /abc
00:22:32.916 [http-nio-8080-exec-1] DEBUG
o.s.w.s.m.m.a.RequestMappingHandlerMapping - Did not find handler method for
[/abc]
00:22:32.916 [http-nio-8080-exec-1] WARN o.s.web.servlet.PageNotFound - No
mapping found for HTTP request with URI
[http://mydomain:8085/contextname/xyz/abc] in DispatcherServlet with name
'contextname'
有什么建议吗?
答案 0 :(得分:0)
删除String pqr
参数,spring不知道该注入什么。
答案 1 :(得分:0)
将方法的签名更改为...
public void myMethod(@RequestParam(required=false) String pqr)
...如果您想偶尔发送该参数,并且您的方法不依赖于它。
Spring并不知道传递给方法的值。