前几天我在公司通过了SpringMVC级别的测评,发现自己知识点不够,答不上一道题。但我想知道正确答案是什么???所以,如果你能帮助我,那就太棒了!
您有以下 PersonController 类并正确定义了 web.xml 和 Spring 上下文
以下请求已使用 POST 方法提交: http://xxxx/person/add?name=John
请填写占位符,以便提交的请求将导致成功保存人员对象,并且只有在请求不包含“id”参数的情况下才会调用方法 addPerson。占位符中的值不应包含空格。
最佳答案
PLACEHOLDER1 :
@Controller
@RequestMapping("person")
PLACEHOLDER2 :
@RequestMapping(value = "add", method = RequestMethod.POST)
你可以从 Spring 官方网站阅读文档。
已编辑:
关于id
,如果你请求的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)
在这里你可以得到 12345 作为 id
。
关于java - Spring MVC RequestMapping 发布方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38738124/