- 当User类中嵌套一个address类,通过json传值的时候需要对address进行特殊处理
- address类
-
public class Address { private String city; private String street; public String getCity() { return city; } public void setCity(String city) { this.city = city; } public String getStreet() { return street; } public void setStreet(String street) { this.street = street; }}
新增user类
-
public class User { private Address address; private String name; private int age; public Address getAddress() { return address; } public void setAddress(Address address) { this.address = address; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } }
js处理
-
var address = {};map['street']=valuemap['city']=value;var user = {}user['address']=address user['name']=zhangsanuser['age']=123$.ajax({ type:"POST", url:url, dataType:"json", contentType:"application/json;charset=utf-8", data:JSON.stringify(user)), success:function(result){ dosomething.... } });
后端接受
-
@PostMapping(value = "/doAdd", produces = "application/json;charset=UTF-8") @ApiOperation("监控&勘测下单") public Result doAdd(@RequestBody User user) { dosomething.... return Result.ok(); }