使用带有Post请求的HTTP dev客户端和Content-Type application/x-www-form-urlencoded
1)只有@RequestBody
请求 - localhost:8080/SpringMVC/welcome In Body - name = abc
码-
@RequestMapping(method = RequestMethod.POST)
public String printWelcome(@RequestBody String body, Model model) {
model.addAttribute("message", body);
return "hello";
}
Run Code Online (Sandbox Code Playgroud)
//按预期将body标记为"name = abc"
2)只有@RequestParam
请求 - localhost:8080/SpringMVC/welcome In Body - name = abc
码-
@RequestMapping(method = RequestMethod.POST)
public String printWelcome(@RequestParam String name, Model model) {
model.addAttribute("name", name);
return "hello";
}
Run Code Online (Sandbox Code Playgroud)
//按预期将名称命名为"abc"
3)两者在一起
请求 - localhost:8080/SpringMVC/welcome In Body - name = abc
码-
@RequestMapping(method = RequestMethod.POST)
public String printWelcome(@RequestBody String body, …Run Code Online (Sandbox Code Playgroud)