Как обновить ссылочный объект в Spring-data rest?
Пример: Класс курса и Учитель, имеющий отношения многие-к-одному, как сменить учителя на определенный курс с помощью Spring-data rest?
GET http://localhost:7070/study-spring-data/course/2
Отклик:
{
"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"
} ]
}
GET http://localhost:7070/study-spring-data/course/2/teacher
Отклик:
{
"_links" : [ {
"rel" : "course.Course.teacher",
"href" : "http://localhost:7070/study-spring-data/course/2/teacher/1"
} ]
}
Как показано выше, курс 2 связан с учителем 1, как заменить учителя на учителя 2?
Я пытался:
успешно обновлено название курса:
PUT http://localhost:7070/study-spring-data/course/2
с полезной нагрузкой
{
"name" : "CSCI-223 Hardcore C++",
}
неудачный при попытке обновить эталонный объект учителя:
PUT http://localhost:7070/study-spring-data/course/2/teacher
с полезной нагрузкой
{
"_links" : [ {
"rel" : "course.Course.teacher",
"href" : "http://localhost:7070/study-spring-data/course/2/teacher/2"
} ]
}
Спасибо!