gpt4 book ai didi

java - 如何使用 Spring Data Rest 在 POST 调用中保存嵌入对象

转载 作者:行者123 更新时间:2023-11-30 02:45:48 27 4
gpt4 key购买 nike

我使用的是 Spring 1.3.3,无法对嵌入对象使用 POST 调用。使用 POST 调用时出现以下错误..

请求

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{
"student": {
"address": {
.....
"zipcode": http://localhost:8082/zipcode/1,

}
},
"id": 1,
"zipcode": http://localhost:8082/zipcode/1,
"name": "John"
}' 'http://localhost:8082/student'

响应错误:

{
"cause": {
"cause": null,
"message": "Unrecognized token 'http': was expecting ('true', 'false' or 'null')\n at [Source: org.apache.catalina.connector.CoyoteInputStream@4a12dfc; line: 3, column: 22]"
},
"message": "Could not read document: Unrecognized token 'http': was expecting ('true', 'false' or 'null')\n at [Source: org.apache.catalina.connector.CoyoteInputStream@4a12dfc; line: 3, column: 22]; nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'http': was expecting ('true', 'false' or 'null')\n at [Source: org.apache.catalina.connector.CoyoteInputStream@4a12dfc; line: 3, column: 22]"
}

地址.java

@Embeddable
public class Address {
private String street;
private String city;
private String state;
// getters and setters

学生.java

@Entity 
@Table(name="Student")
@SecondaryTable(name="Student_ADDRESS",
pkJoinColumns=@PrimaryKeyJoinColumn(name="Student_ID"))
public class Student {
@Id private int id;
private String name;

@Embedded
@AttributeOverrides({
@AttributeOverride(name="street", column=@Column(table="Student_ADDRESS")),
@AttributeOverride(name="city", column=@Column(name="CITY", table="Student_ADDRESS")),
@AttributeOverride(name="state", column=@Column(name="STATE", table="Student_ADDRESS")),
})
private Address address;
private Zipcode zipcode;
//getters and setters

邮政编码.java

@Entity
public class Zipcode {
@Id
public int id;
public String code;
}

如何保存嵌入的对象?请提供您的意见。

最佳答案

它告诉您应该在网址周围添加“”。

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{
"student": {
"address": {
.....
"zipcode": "http://localhost:8082/zipcode/1",

}
},
"id": 1,
"zipcode": "http://localhost:8082/zipcode/1",
"name": "John"
}' 'http://localhost:8082/student'

关于java - 如何使用 Spring Data Rest 在 POST 调用中保存嵌入对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40218373/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com