Spring Data REST URI vs. entity ID

后端 未结 2 1471
南旧
南旧 2020-12-20 16:49

Spring Data REST (and Spring HATEOAS in particular) decouples RESTful IDs (viz., URIs) from entity IDs, and I\'m having trouble linking them back up when saving new objects.

相关标签:
2条回答
  • 2020-12-20 17:16

    Have you looked at https://github.com/SpringSource/spring-data-rest/wiki/Embedded-Entity-references-in-complex-object-graphs?

    Simply put, the exporter will de-reference Link objects if it finds them in place of a relationship or managed object (another entity that has an exported Repository).

    Assuming your linked property is called "category", then you could create a new Ticket like:

    POST /tickets
    Content-Type: application/json
    
    {
      "description": "Description of the ticket or issue",
      "category": {
        "rel": "category.Category",
        "href": "http://localhost:8080/categories/1"
      }
    }
    
    0 讨论(0)
  • 2020-12-20 17:22

    Apprently in the newer versions of Spring Data Rest, this should do it:

    POST /tickets
    Content-Type: application/json
    
    {
      "description": "Description of the ticket or issue",
      "category": "http://localhost:8080/categories/1"
    }
    

    Going by Oliver Gierke's comment at Spring Data Rest 2.0.0.RELEASE Breaks Code Working Previously With RC1

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