示例:类 Course 和 Teacher 具有多对一关系,如何通过 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"
} ]
}
谢谢!