spring-data-rest - Spring 数据 REST : Update a resource´s association using proper HTTP method

标签 spring-data-rest

我正在使用 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/

相关文章:

hibernate - Spring 数据休息 : "Date is null" query throws an postgres exception

java - 使用 Spring Data Rest 为 Controller 和存储库提供相同的 url 映射

mongodb - 在 Spring 数据的 RepositoryRestResource 中急切加载 MongoDB @DBRef

java - 从 ResourceProcessor 中摘录投影和自定义链接

java - 使用 Spring Data REST 实现更新深度嵌套 JSON 结构的最佳方法是什么?

http - 如何构造一个不需要主体的 POST 请求

spring-data-neo4j - 非关系属性未在 Spring Data Rest Neo4j 输出中的引用实体上公开

spring-boot - StreamingResponseBodyReturnValueHandler 不使用 applicationTaskExecutor

Spring Data REST 的 QueryDSL 集成,用于查询实体中集合映射的子属性

java - Spring Boot 和 JPA 存储库 — 如何按 ID 过滤 GET