Paginate sub-resources in Spring Data Rest 2.1

前端 未结 2 376
遥遥无期
遥遥无期 2020-12-16 06:02

I use Spring Data Rest 2.1.1 Release with the default configuration. Considering the following resource:

GET /communities/MyCommunity

{
    \"creationDate\"         


        
2条回答
  •  一向
    一向 (楼主)
    2020-12-16 06:26

    The answer is pretty simple: you can't. Here's the rationale:

    Association resource represent the association between a a primary entity and one or many others. So to render these resources we lookup the primary entity and just access the property. This means, there's no repository usage and no place pagination can be applied as the entire mechanism is store agnostic. We operate on the entity instance The mechanism how associations are loaded is highly store specific.

    So if you have object associations in your domain model already you're totally bound to the way the store treats associations. So even if you applied pagination, you would have to read all of the related objects in the first place to obtain their ids.

    As a work around you could fall back to ids only and manually expose a resource right at that path which will use the ids and a dedicated query method on the repository of the associated entity.

提交回复
热议问题