萌新参考向
@RequestParam
@RequestParam获得的参数是URL中拼接的参数
例如:
请求
http://localhost:8080/testController/test0?name=abc&age=12&number=999
controller:
@RequestMapping("/test0")
public void test0(@RequestParam String name,@RequestParam int age) {....}
那么url后面的name和age会被解析出来,当然,如果你的命名不是那么对应的上的话可以使用下面的方式
@RequestMapping("/test1")
public void test1(@RequestParam("name") String myname,@RequestParam("age") String myage) {....}
一些应用场景:
①比较简单的参数
②需要一些验证和默认值的参数
@RequestBody
@RequestBody获取的是http请求中body的部分
前提:在http请求的headers里面Content-Type为application/json
有这样一个请求:http://localhost:8080/testController/test2<