在投影中删除Spring数据休息自链接模板。

问题描述 投票:1回答:1
{
  "_embedded" : {
    "patient" : {
      "firstName" : "Kidus",
      "_links" : {
        "self" : {
          "href" : "http://localhost:8090/api/patients/2{?projection}",
          "templated" : true
        },
    }
}

如你所见,我有一个嵌入式实体(病人)。它返回所有数据,包括实体的链接,但链接是模板化的。我没有使用前端的HATEOAS客户端,我也不打算改变这个方向。所以我需要一个正常的非模板化的链接。有没有什么非黑客的方法来实现这个目标?

spring-boot spring-data spring-data-jpa spring-data-rest
1个回答
0
投票

你可以用这种方式强制展开模板。

@GetMapping("/myresources/{id}")
public EntityModel<MyResource> myResource(String id) {

    MyResource resource = ...;
    return new EntityModel<>(
                  resource,
                  linkTo(methodOn(getClass()).myResource(id)).withSelfRel().expand(id));
}
© www.soinside.com 2019 - 2024. All rights reserved.