11

Spring Data REST を使用しており、Spring REST を使用して多対 1 の関係を変更しようとしていますが、適切な http 呼び出しを機能させることができません。

私のエンティティは次のようになります (POST などを使用した作成などの基本的な呼び出しは正常に機能します):

{
  「ID」:70、
  "productId" : yyy,
  "商品割引" : 10,
  「バージョン」: 0,
  "説明": "xxx",
  "_links": {
    "自己": {
      "href": "http://localhost:8080/rest/rules/70"
    }、
    "時間定義": {
      "href" : "http://localhost:8080/rest/rules/70/timedefinition"
    }
  }
}

ID 1 の現在の timedefinition を 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

次のエラーが表示されます。

タイプ java.lang.String からタイプ domain.TimeDefinition への値 '0' の変換に失敗しました。ネストされた例外は java.lang.IllegalArgumentException: クラス domain.TimeDefinition に間違ったタイプの ID を提供しました。予想: クラス java.lang.Integer、クラス 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":"リストまたはマップではないプロパティ参照を更新するには、リンクを 1 つだけ送信する必要があります。"

http://docs.spring.io/spring-data/rest/docs/2.0.1.RELEASE/reference/html/のメイン リファレンスは、残念ながら上記のトピックに関する情報をあまり提供していません。

エンティティの関連付けを更新するための適切な REST クエリ形式に関する洞察と説明は大歓迎です!

4

3 に答える 3

14

正解は私のコメントの通りです:

curl -v -X PUT -H "Content-Type: text/uri-list" -d "http://localhost:8080/rest/timedefinition/0" http://localhost:8080/rest/rules/70/timedefinition
于 2014-04-11T09:41:42.470 に答える