如果间接引用,则Spring Data Rest Projection链接会有所不同

时间:2017-06-27 12:06:05

标签: java spring-data spring-data-rest

我有一个Spring Data Rest项目,它有一些关系,但我发现HATEOAS链接是不同的,这取决于是否直接调用投影而不是通过另一个投影引用。

我正在这样做,以便我可以加载骨架结构以进行快速初始加载,然后在需要更多详细信息时直接查询实体。例如,如果投影设置为:

,则直接跳过实体
@Projection(name="userDetails")
public Interface UserProjection {
    String getName();
    List<RoomProjection> getRooms();
}

@Projection(name="RoomDetails")
public Interface RoomProjection {
    String getName();
    List<ComputerProjection> getComputers();
}

@Projection(name="ComputerDetails")
public Interface ComputerProjection {
    String getName();
}

查询GET /users?projection=userDetails的回复告诉我们:

{
    "_embedded": {
        "users": [
            {
                "name": "User One",
                "rooms": [
                    {
                        "name": "Room One",
                        "computers": [
                            {
                                "name": "Computer One",
                                "_links": {
                                    "self": {
                                        "href": "http://localhost:8080/computers/1{?projection}",
                                        "templated": true
                                    }
                                }
                            }
                        ],
                        "_links": {
                            "self": {
                                "href": "http://localhost:8080/rooms/1{?projection}",
                                "templated": true
                            },
                            "computers": {
                                "href": "http://localhost:8080/rooms/1/computers"
                            }
                        }
                    }
                ],
                "_links": {
                    "self": {
                        "href": "http://localhost:8080/users/1"
                    },
                    "user": {
                        "href": "http://localhost:8080/users/1{?projection}",
                        "templated": true
                    },
                    "rooms": {
                        "href": "http://localhost:8080/users/1/rooms"
                    }
                }
            }
        ]
    }
}

正如您所看到的,房间和计算机的自我链接获取投影参数并丢失自引用链接,这在用户中不存在。但除非我通过嵌入式投影向下钻取,否则我似乎无法提供轻量级概述。

是否有一种简单的方法可以让自我链接保持一致而不包括投影?

0 个答案:

没有答案
相关问题