2017-12-20 2 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 

질문에 ID를 값으로 채우는 방법은 무엇입니까?

_links [self, entity ...]의 모든 조합을 시도했습니다.

답변

0

일반적으로 많은 자바 틱 프레임 워크는 JSON에서 전달 된 ID를 바인드하지 않습니다. 일반적으로 ID는 경로에 있습니다. ID를 전달한 다음 리포지토리에서 찾으려합니다.

이 경로에 ID가 삭제 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

정확합니다. 그러나 우리가 ID가 클라이언트 측에서만 자기 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에서 객체를 deserialize하는 것입니다. – notanormie