2015-04-20 48 views
1

我正在Spring-data-rest中开发一个应用程序。我正在测试来自POSTMAN客户端的POST请求,以测试数据是否插入到数据库中。在我的数据库中,我有一个cartItems表。我可以发布数据,同时我POST JSON如下:商品,购物车和商品类型是外键引用。POSTMAN中的Spring-data-rest测试

{ 
"rate": 500, 
"quantity": 1, 
"amount": 500, 
"createdAt": "2015-04-12T23:40:00.000+0000", 
"updatedAt": "2015-04-14T21:35:20.000+0000", 
"merchandise": "http://localhost:8080/sportsrest/merchandises/10", 
"cart":"http://localhost:8080/sportsrest/carts/902", 
"merchandiseType":"http://localhost:8080/sportsrest/merchandiseTypes/1" 
    } 

但是当我发布的数据,下面我得到的错误:不是URL的商品,我把我已经测试了商品表JSON的POST请求的商品JSON:

{ 
"rate": 500, 
"quantity": 1, 
"amount": 500, 
"createdAt": "2015-04-12T23:40:00.000+0000", 
"updatedAt": "2015-04-14T21:35:20.000+0000", 
"merchandise": { 
    "id": 4, 
    "shortDescription": "white football", 
    "rate": 500, 
    "updatedAt": "2015-04-24T18:30:00.000+0000", 
    "createdAt": "2015-04-20T18:30:00.000+0000", 
    "longDescription": "test description for binary 1001", 
    "type": "1" 
    }, 
"cart":"http://localhost:8080/sportsrest/carts/902", 
"merchandiseType":"http://localhost:8080/sportsrest/merchandiseTypes/1" 

}

我收到以下错误:

{ 
"cause": { 
"cause": { 
"cause": null, 
"message": "Template must not be null or empty!" 
    }, 
"message": "Template must not be null or empty! (through reference chain: co.vitti.sports.bean.CartItem[\"merchandise\"])" 
}, 
"message": "Could not read JSON: Template must not be null or empty! (through reference chain: co.vitti.sports.bean.CartItem[\"merchandise\"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Template must not be null or empty! (through reference chain: co.vitti.sports.bean.CartItem[\"merchandise\"])" 
} 

可以将部分一个p租赁帮助我为什么我得到这个错误。 谢谢。

回答

0

我想你没有提供Content-Type:application/json头。

+0

感谢您的重播。我提供了Content-Type作为Application/json。我们可以像上面那样将引用表的链接作为JSON发布吗? – MAK

+0

嘿,抱歉我的草率回答。我只是没有完整地阅读你的问题。默认情况下,Spring Data Rest会试图找出发送的数据。为了与关联这么做,它会考虑URI。如果你真的需要使用后面的例子,你应该写一个自定义的解串器。 –

+0

没关系。感谢您的答复。 – MAK

0

尝试用“@RestResource(exported = false)”注释您的“MerchandiseRepository”。

相关问题