Spring Data Rest - Include nested resource in _embedded

后端 未结 2 2062
陌清茗
陌清茗 2021-01-07 03:55

I\'m developing a Spring Boot Application for a shopping list. For this I use Spring Data Rest to export my entities through a REST API.

My Architecture looks like t

相关标签:
2条回答
  • 2021-01-07 04:57

    Try adding this Accept header when you make the request:

    Accept: application/x-spring-data-verbose+json
    

    Also, take a look at this post where this is explained in details.

    0 讨论(0)
  • 2021-01-07 05:00

    Define an excerpt projection for Article and configure into its repository with excerptProjection

    Any resource that has defined an excerpt projection will be added to _embedded part fo the response. This applies to collecion resources of associations.

    Read more at https://stackoverflow.com/a/30297320/1203628 or Spring Data REST reference documentation

    An excerpt projection is used whenever an instance of the target type (Article in your case) is used within in an _embedded clause. Thus the excerpt is some kind of preview used everywhere the resource itself is not rendered but pointed to. This is usually the case from collection resources or for associations. Read more on this topic in the Spring Data REST reference documentation.

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