java Spring MVC RequestMapping Post方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38738124/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Spring MVC RequestMapping Post method
提问by mr. VitaliiH
few days ago I passed SpringMVC level evaluation test on my company, and I found that I don't have enough knowledge to answer one question. But I'm wondering what is the correct answer??? So it will be awesome if You help me!
前几天在我公司通过了SpringMVC级别的评测,发现自己的知识不够回答一个问题。但我想知道正确答案是什么???所以如果你帮助我,那就太棒了!
You have the following PersonController class and correctly defined web.xml and Spring context
您有以下 PersonController 类并正确定义了 web.xml 和 Spring 上下文
The following request has been submitted using POST method: http://xxxx/person/add?name=John
以下请求已使用 POST 方法提交: http://xxxx/person/add?name=John
Please, fill the placeholders so that submitted request would result into person object being saved successfully and method addPerson would be called only in case request doesn't contain "id" parameter. Values in placeholders should not contain spaces.
请填写占位符,以便提交的请求将导致成功保存 person 对象,并且只有在请求不包含“id”参数的情况下才会调用方法 addPerson。占位符中的值不应包含空格。
回答by Blank
PLACEHOLDER1:
占位符1:
@Controller
@RequestMapping("person")
PLACEHOLDER2:
PLACEHOLDER2:
@RequestMapping(value = "add", method = RequestMethod.POST)
And you can read document from Spring official site.
您可以从 Spring 官方网站阅读文档。
Edited:
About id
, if you request url is like http://xxxx/person/add/12345?name=John, then you can do it like this:
编辑:
Aboutid
,如果您请求的 url 类似于http://xxxx/person/add/12345?name=John,那么您可以这样做:
@RequestMapping(value = "add/{id}", method = RequestMethod.POST)
public String addPerson(@RequestParam("name") String name, @PathVariable("id") String id)
here you can get 12345 as id
.
在这里你可以得到 12345 作为id
.