How to update reference object in Spring-data rest?

前端 未结 3 1907
陌清茗
陌清茗 2020-12-29 13:34

Example: class Course and Teacher having many-to-one relationship, how to change teacher for a certain course via Spring-data rest?

GET http         


        
相关标签:
3条回答
  • 2020-12-29 13:49

    Using httpie PATCH instead of PUT works for me:

    http PATCH :7070/study-spring-data/course/2 teacher="http://localhost:7070/study-spring-data/teacher/2"
    

    Again, this does not work with PUT.

    0 讨论(0)
  • 2020-12-29 13:51

    I think you should have to check the Cascading for Course. Because if you are updating the course , then it should update your teacher also, if Cascading update or All is to be assigned for your course.

    0 讨论(0)
  • 2020-12-29 13:59

    How about something like 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 is a way suggested by O'Reilly's Spring Data book.

    0 讨论(0)
提交回复
热议问题