保存相关实体spring数据rest HAL-JSON
我有以下问题 我有一个SpringDataREST的基本配置(没有花哨,没有定制) 使用SpringDataRESTWebMVC2.0.0版本和SpringDataJPA1.5.0版本 甲级保存相关实体spring数据rest HAL-JSON,json,spring,rest,hateoas,hal-json,Json,Spring,Rest,Hateoas,Hal Json,我有以下问题 我有一个SpringDataREST的基本配置(没有花哨,没有定制) 使用SpringDataRESTWebMVC2.0.0版本和SpringDataJPA1.5.0版本 甲级 @Entity public class A { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private int id private String name; @ManyToMany priv
@Entity
public class A {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id
private String name;
@ManyToMany
private List<B> b;
// getters setters
}
我得到一个201 http代码,但没有保存实体
有人已经尝试过了吗?尝试使用URL
POST http://localhost:8080/api/a
Content-Type: application/json
{
"name" : "Name of A",
"b": "http://localhost:8080/api/b/1"
}
或者,在你的情况下,可能是
"b" : ["http://localhost:8080/api/b/1"]
因为A.b是一个列表,因此您需要提交一个数组。不过,他没有对此进行测试
这应该是自Spring2.0以来的有效方法(请参阅),对我来说效果很好。您解决过这个问题吗?我也有类似的问题。
@Repository
@RestResource(rel = "b", path = "b")
public interface BRepository extends PagingAndSortingRepository<B, Integer> {
}
POST http://localhost:8080/api/a
{
"name": "Name of A",
"b": {
"rel": "b",
"href": "http://localhost:8080/api/b/1"
}
}
POST http://localhost:8080/api/a
Content-Type: application/json
{
"name" : "Name of A",
"b": "http://localhost:8080/api/b/1"
}
"b" : ["http://localhost:8080/api/b/1"]