2017-12-20 8 views
1

は、私は次のメソッドを持つスプリングRepositoryRestControllerを持っています。 春ブートデータの残りのポストエンティティ

は、例えばEntityクラスは次のようになります。

public Entity { 
Long id; 

String firstField; 

String secondField; 

EntityB relatedEntity; 

} 

ポスティングはそのフィールドの値を、以下で、エンティティのinstaceにエンドポイントデシリアライズになります

{ 
    id: 1, 
    firstField: "someThing", 
    secondField: "BUMP", 
    relatedEntity: "<root>/api/entityB/1: 
} 

をエンドポイントするJSONを次

Entity: 
    id = null 
    firstfield = "someThing" 
    secondField = "BUMP", 
    relatedEntity = instance of EntityB.class with everything related 

私が期待するものは:

Entity: 
    id = 1 
    firstfield = "someThing" 
    secondField = "BUMP", 
    relatedEntity = instance of EntityB.class with everything related 

質問にはどのように値を設定するのですか?

_links [self、entity ...]のすべての組み合わせを試しました。

答えて

0

一般的に、java-ishフレームワークの多くは、JSONで渡されたIDをバインドしません。通常、IDはパス内にあります。 IDを渡してリポジトリで参照したいとします。

これは、パスのidとDELETE HTTPと呼ばれることが期待され、削除RepositoryRestControllerのようになります。

@RequestMapping(method = RequestMethod.POST, value = "/doSomethingWithEntity/{id}") 
@ResponseBody 
    public ResponseEntity deleteEmployeeSalaryPosition(@PathVariable Long id, @RequestBody Resource<Entity> entity) { 
:、あなたの例のためにあなたがパスにIDを入れたい https://docs.spring.io/spring-data/rest/docs/1.0.x/api/org/springframework/data/rest/webmvc/RepositoryRestController.html

しかし、とにかく

その方法が何であるかに応じて、要求本体をまったく渡す必要はないかもしれません。

+0

これは正しいです。しかし、我々はアイデアがクライアント側にのみ自己のURLを公開していないという考えに従っている場合。あなたは私のために関係からそれを回復するために春のブートを提供する方法を知っていますか? – notanormie

+0

これは関連しているようです:https://stackoverflow.com/questions/24936636/while-using-spring-data-rest-after-migrating-an-app-to-spring-boot-i-have-obser – brub

+0

これはそれ以外の方法では、exposingIdsはクライアントに送信するためですが、私が達成しようとしているのはidを持つJSONからオブジェクトを逆シリアル化することです。 – notanormie

関連する問題