该注解用于获取请求体数据(body),get没有请求体,故而一般用于post请求
可以用与之对应的一个类接收
@PostMapping("/test01")@ResponseBodypublic UserDto test01(@RequestBody UserDto userDto) {return userDto;}@PostMapping("/test02")@ResponseBodypublic String test02(@RequestBody String str) {return str;}


**注意,如果要传多个参数过去只能将其封装成一个类,如果是出现了多个@RequestBody注解访问的时候会报400错误,例如下面这种代码就是**``**错误**``**的**
/
@PostMapping("/requestBody")@ResponseBodypublic Map<String,String> requestBody(@RequestBody(required = true) String id,@RequestBody(required = true) String name,@RequestBody(required = false) String sex,@RequestBody(required = false) String age){Map<String,String> map = new HashMap<>();map.put("id","id");map.put("name","name");return map;}注意,一个post只有一个body,不能一个一个匹配
用于读取 Request 请求(可能是 POST,PUT,DELETE,GET 请求)的 body 部分并且Content-Type 为 application/json 格式的数据,接收到数据之后会自动将数据绑定到 Java 对象上去。系统会使用HttpMessageConverter或者自定义的HttpMessageConverter将请求的 body 中的 json 字符串转换为 java 对象。
