如果您有这样的模型:
@Entitypublic class User { //.. private String name; @oneToMany(mappedBy = "user") private Set<Address> addresses = new HashSet<>(); //..}@Entitypublic class Address { //.. @ManyToOne private User user; //..}那么你可以发布新的
User与它
addresses这样的:
POST http://localhost:8080/api/users{ "name" : "user1", "addresses" : [ "http://localhost:8080/api/addresses/1", "http://localhost:8080/api/addresses/2" ]}在发布新用户之前,地址ID#1和ID#2必须已经保留。



