2016-10-24 31 views
0

我使用的是Spring 1.3.3,我無法使用POST調用嵌入對象。收到以下錯誤,而使用POST通話..如何使用Spring Data Rest在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: [email protected]; line: 3, column: 22]" 
    }, 
    "message": "Could not read document: Unrecognized token 'http': was expecting ('true', 'false' or 'null')\n at [Source: [email protected]; line: 3, column: 22]; nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'http': was expecting ('true', 'false' or 'null')\n at [Source: [email protected]; 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", 
       [email protected](name="Student_ID")) 
public class Student { 
    @Id private int id; 
    private String name; 

    @Embedded 
    @AttributeOverrides({ 
     @AttributeOverride(name="street", [email protected](table="Student_ADDRESS")), 
     @AttributeOverride(name="city", [email protected](name="CITY", table="Student_ADDRESS")), 
     @AttributeOverride(name="state", [email protected](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; 
} 

如何保存嵌入對象?請提供您的輸入。

+0

請親切地告訴什麼是嵌入式對象的名稱 – Taimur

回答

1

它告訴你,你應該在網址周圍放置「」。

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' 
+0

謝謝@ mh-dev !!它正在工作...... :) – SST

+0

如果兩個關聯對象都存在,那麼我們如何創建關係,並將數據放入組合表中 – Taimur

相關問題