示例:课程和教师有多对一的关系,如何通过Spring-data rest改变某个课程的教师?
GET http://localhost:7070/study-spring-data/course/2
Run Code Online (Sandbox Code Playgroud)
响应:
{
"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
Run Code Online (Sandbox Code Playgroud)
响应:
{
"_links" : [ {
"rel" : "course.Course.teacher",
"href" : "http://localhost:7070/study-spring-data/course/2/teacher/1"
} ]
}
Run Code Online (Sandbox Code Playgroud)
如上所示,课程2与教师1相关,如何将教师改为教师2?
我试过了:
成功更新课程名称:
PUT http://localhost:7070/study-spring-data/course/2
有效载荷
{
"name" : "CSCI-223 Hardcore C++",
}
Run Code Online (Sandbox Code Playgroud)
尝试更新参考对象教师时失败:
PUT http://localhost:7070/study-spring-data/course/2/teacher
Run Code Online (Sandbox Code Playgroud)
有效载荷
{
"_links" : [ {
"rel" : "course.Course.teacher",
"href" : "http://localhost:7070/study-spring-data/course/2/teacher/2" …Run Code Online (Sandbox Code Playgroud)