Spring MVC 3.0 带注释的控制器无法与 JQuery $.post() 一起使用
在 Spring MVC 控制器中,我尝试访问 JQuery 简单帖子发送的名称。 我收到错误在 @RequestMapping* 中找不到 @PathVariable [name] 我哪里出错了?
JQuery Post
$.post("addName.htm",{ name: "John"});
Spring Controller
@RequestMapping(value = "/addName.htm", method = RequestMethod.POST)
public void setAllocations(@PathVariable String name) {
System.out.println("inside Setting value.... ");
System.out.println(name);
}
我收到错误
在@RequestMapping 中找不到@PathVariable [name]
In the Spring MVC controller i am trying to access the name sent by the JQuery simple post.
I am getting error Could not find @PathVariable [name] in @RequestMapping*
Where i am going wrong?
JQuery Post
$.post("addName.htm",{ name: "John"});
Spring Controller
@RequestMapping(value = "/addName.htm", method = RequestMethod.POST)
public void setAllocations(@PathVariable String name) {
System.out.println("inside Setting value.... ");
System.out.println(name);
}
I am getting error
Could not find @PathVariable [name] in @RequestMapping
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这不是
@PathVariable
,您必须使用@RequestParam
代替。试试这个:这就是区别:
http://yourhost/{name}/addName.html
http://yourhost/addName.html?name={name}
That is not a
@PathVariable
, you have to use a@RequestParam
instead. Try this:This is the difference:
http://yourhost/{name}/addName.html
http://yourhost/addName.html?name={name}
您应该使用
@RequestParam
而不是docs:
You should use
@RequestParam
instead of@PathVariable
From the docs: