我有 Angular 发送的 JSON 字符串:
{
"transaction_id": "1234",
"usage": "Test Usage",
"billing_address": {
"first_name": "name",
"last_name": "name",
"address1": "street 1234",
"zip_code": "11923"
},
"shipping_address": {
"first_name": "name",
"last_name": "name",
"address1": "street 1234",
"zip_code": "11923"
}
}
Java代码:
public class DTO {
private String transaction_id;
private String usage;
private BillingAddress billingAddress;
private ShippingAddress shippingAddress;
... getter/setter
}
public class BillingAddress {
private String firstName;
private String lastName;
private String address1;
private String zip_code;
... getter/setter
}
public class ShippingAddress {
private String firstName;
private String lastName;
private String address1;
private String zip_code;
... getter/setter
}
弹簧端点:
@PostMapping(value = "/{id}", consumes = { MediaType.APPLICATION_JSON_VALUE }, produces = { MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<?> handleWpfMessage(@PathVariable("id") id,
@RequestBody DTO data){
....
}
映射内部对象billing_address以及shipping_address正确映射值的正确方法是什么?我是否需要添加注释才能正确映射它们?
慕沐林林
哆啦的时光机
撒科打诨
相关分类