我正在使用 Spring Data REST,并且我正在尝试使用 Spring REST 更改多对一关系,但是我无法获得正确的 http 调用。
我的实体看起来像这样(使用 POST 创建等基本调用工作正常):
{
“身份证”:70,
"productId": yyy,
“产品折扣”:10,
“版本”:0,
"描述": "xxx",
“_链接”:{
“自己” : {
"href": "http://localhost:8080/rest/rules/70"
},
“时间定义”:{
“href”:“http://localhost:8080/rest/rules/70/timedefinition”
}
}
}
我想将 ID 1 的当前时间定义更改为 ID 2。
我尝试了很多不同的调用类型,但有不同的错误。下面的调用不起作用。
curl -X PUT -H "Content-Type: text/uri-list"-d 'http://localhost:8080/rest/timedefinition/1' http://localhost:8080/rest/rules/70/timedefinition
收到以下错误:
Failed to convert from type java.lang.String to type domain.TimeDefinition for value '0'; nested exception is java.lang.IllegalArgumentException: Provided id of the wrong type for class domain.TimeDefinition. Expected: class java.lang.Integer, got class java.lang.Long
另一个例子是这样的:
curl -X PUT -H "Content-Type: application/json"-d '{"timedefinition": {"href": "http://localhost:8080/rest/timedefinition/0", "rel": "timedefinition "} }' http://localhost:8080/rest/rules/70/timedefinition
我得到的错误是:
"message":"Must send only 1 link to update a property reference that isn't a List or a Map."
主要引用在 http://docs.spring.io/spring-data/rest/docs/2.0.1.RELEASE/reference/html/不幸的是,没有提供关于上述主题的太多信息。
非常感谢有关更新实体关联的正确 REST 查询格式的任何见解和解释!
最佳答案
正确答案是我的评论:
curl -v -X PUT -H "Content-Type: text/uri-list" -d "http://localhost:8080/rest/timedefinition/0" http://localhost:8080/rest/rules/70/timedefinition
关于spring-data-rest - Spring 数据 REST : Update a resource´s association using proper HTTP method,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22499819/