4
我有如下問題保存相關實體春天數據休息HAL-JSON
我有春天數據休息(沒有什麼幻想,沒有自定義)的基本配置。
使用彈簧 - 數據 - 其餘-webmvc 2.0.0 RELEASE和彈簧數據JPA 1.5.0 RELEASE
A類
@Entity
public class A {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id
private String name;
@ManyToMany
private List<B> b;
// getters setters
}
B類
@Entity
public class B {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id
private String nameb;
@ManyToMany(mappedBy = "b")
private List<A> a;
// getters setters
}
儲存庫中的
@Repository
@RestResource(rel = "a", path = "a")
public interface ARepository extends PagingAndSortingRepository<A, Integer> {
}
存儲庫B
@Repository
@RestResource(rel = "b", path = "b")
public interface BRepository extends PagingAndSortingRepository<B, Integer> {
}
當我保存的實體工作得很好,但我不知道如何保存的關係
例如保存「A」是「B」使用http
這是我從這個答案https://stackoverflow.com/a/13031580/651948
POST http://localhost:8080/api/a
{
"name": "Name of A",
"b": {
"rel": "b",
"href": "http://localhost:8080/api/b/1"
}
}
嘗試的最後一件事,我得到一個201 HTTP代碼,但不保存實體內。
有人試過這個嗎?
你有沒有解決過這個問題?我也有類似的問題。 – clmarquart