Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.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
Java 如何使用Spring数据Rest在POST调用中保存嵌入对象_Java_Spring_Spring Data Rest - Fatal编程技术网

Java 如何使用Spring数据Rest在POST调用中保存嵌入对象

Java 如何使用Spring数据Rest在POST调用中保存嵌入对象,java,spring,spring-data-rest,Java,Spring,Spring Data Rest,我正在使用Spring1.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,

我正在使用Spring1.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]"
}
Address.java

@Embeddable
public class Address {
    private String street; 
    private String city; 
    private String state;
    // getters and setters
Student.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
Zipcode.java

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

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

它告诉您应该在URL周围放置“”

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'

若两个关联的对象都存在,那个么我们如何创建关系,并将数据放在复合表中呢?请告诉我们这里嵌入的对象的名称