@RequestBody , 需要使用 传入 json格式,
专门为了
application/json
和application/xml
等设置的
-
会自动装配到 实体类中
-
代码
@RequestMapping(value="test3",method = RequestMethod.POST) public void test3(@RequestBody UserDto userDto){ // from-data 报错 415 // x-www-form-uriencodéd 报错 415 // json 报错 400 System.out.println(userDto); }
**package com.example.hello_reqquestparam.common.dto; public class UserDto { private String name; private String password; private int age; public int getAge() { return age; } @Override public String toString() { return "UserDto{" + "name='" + name + '\'' + ", password='" + password + '\'' + ", age=" + age + '}'; } public void setAge(int age) { this.age = age; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getName() { return name; } public void setName(String name) { this.name = name; } }**
-
-
一般用于 post 请求