java - How to update reference object in Spring-data rest? -
example: class course , teacher having many-to-one relationship, how change teacher course via spring-data rest?
get http://localhost:7070/study-spring-data/course/2
response:
{ "name" : "csci-338 hardcore java", "_links" : [ { "rel" : "course.course.teacher", "href" : "http://localhost:7070/study-spring-data/course/2/teacher" }, { "rel" : "self", "href" : "http://localhost:7070/study-spring-data/course/2" } ] } http://localhost:7070/study-spring-data/course/2/teacher
response:
{ "_links" : [ { "rel" : "course.course.teacher", "href" : "http://localhost:7070/study-spring-data/course/2/teacher/1" } ] }
as above shown, course 2 associated teacher 1, how change teacher teacher 2?
i have tried:
successfully updated course name:
put http://localhost:7070/study-spring-data/course/2
payload
{ "name" : "csci-223 hardcore c++", }
unsuccessful when try update reference object teacher:
put http://localhost:7070/study-spring-data/course/2/teacher
with payload
{ "_links" : [ { "rel" : "course.course.teacher", "href" : "http://localhost:7070/study-spring-data/course/2/teacher/2" } ] }
thanks!
how this:
curl -v -x put -h "content-type: text/uri-list" \ -d "http://localhost:7070/study-spring-data/teacher/1" \ http://localhost:7070/study-spring-data/course/123/teacher
this way suggested o'reilly's spring data book.
Comments
Post a Comment