Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
保存相关实体spring数据rest HAL-JSON_Json_Spring_Rest_Hateoas_Hal Json - Fatal编程技术网

保存相关实体spring数据rest HAL-JSON

保存相关实体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

我有以下问题

我有一个SpringDataREST的基本配置(没有花哨,没有定制)

使用SpringDataRESTWebMVC2.0.0版本和SpringDataJPA1.5.0版本

甲级

@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"]