我有带有方法的控制器类:
@RequestMapping(value = "/createchild", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public void createChild(@RequestBody Child child) {
childService.createChild(child);
}
而且当我使用此json时,它是有效的:
{
"childfullname":"Lok Maen",
"password": "jfsddsf1",
"phonenumber": "+79695426314"
}
但是如果我要发布这样的内容:
{
"another parameter": "123",
"child": {
"childfullname":"Lok Maen",
"password": "jfsddsf1",
"phonenumber": "+79155426314"
}
}
它不起作用。
子类:
@Entity
@Table(name = "child", schema = "cheer")
public class Child {
@Id
@Column(name = "childid")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long childId;
@JsonProperty("childfullname")
@Column(name = "childfullname")
private String childFullName;
@JsonProperty("password")
@Column(name = "password")
private String password;
// another code
}
我如何修改代码以在JSON正文中发布另一个参数?