Spring Data REST URI vs. entity ID

后端 未结 2 1474
南旧
南旧 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"
      }
    }
    

提交回复
热议问题