2017-05-20 2 views
0

URL (http://127.0.0.1:8080/authors/1)을 도메인 객체로 변환하려면 어떻게해야합니까?Spring RESTful 서비스 대상 URL

나는 내 클라이언트가 외래 키로 URL을 제출하게하고 어떻게 든 해결해야한다.

예를 들어 내가 잘하지만, 물론 0 튜토리얼이나 예제 소리라는 클래스 UriToEntityConverter을 발견 저자 1

POST /books 
{"title":"Harry Potter", "author":"http://127.0.0.1:8080/authors/1" 

와 함께 책을 만들려고합니다.

@RestController에서 내 개체를 제공하고 있습니다.

+0

어쩌면이 테스트 [UriToEntityConverterUnitTests] (https://github.com/spring-projects/spring-data-rest를 변수를 저장할 수 /blob/master/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/UriToEntityConverterUnitTests.java) 도움이 될 수 있습니다 ... – Cepr0

답변

0

단순히 요청 매핑을 사용하여 경로를 정의하고 pathVariable 주석을 사용하여

@RequestMapping(value="/authors/{id}", method=RequestMehtod.POST) 
public RequestEntity<String> doSomething(@PathVariable("id") long id) //id will contain your id