繁体   English   中英

在Spring Data REST中使用嵌套投影

[英]Using Nested Projections in Spring Data REST

如何在Spring Data REST中OrderProjection使用ItemProjection渲染项目的下方获得期望的输出

GET / orders / 1?projection = with_items

投影:

@Projection(name = "summary", types = Item.class)
public interface ItemProjection {
    String getName();
}

@Projection(name = "with_item", types = Order.class)
public interface OrderProjection {
    LocalDateTime getOrderedDate();
    Status getStatus();
    Set<ItemProjection> getItems(); // this is marshalling as Set<Item> (full Item graph)
}

当前作为输出获取:

{
  "status" : "PAYMENT_EXPECTED",
  "orderedDate" : "2014-11-09T11:33:02.823",
  "items" : [ {
    "name" : "Java Chip",
    "quantity" : 1,
    "milk" : "SEMI",
    "size" : "LARGE",
    "price" : {
      "currency" : "EUR",
      "value" : 4.20
    }
  } ],
  "_links" : {
    "self" : {
      "href" : "http://localhost:8080/orders/1{?projection}",
      "templated" : true
    },
    "restbucks:items" : {
      "href" : "http://localhost:8080/orders/1/items"
    },
    "curies" : [ {
      "href" : "http://localhost:8080/alps/{rel}",
      "name" : "restbucks",
      "templated" : true
    } ]
  }
}

预期产量:

{
  "status" : "PAYMENT_EXPECTED",
  "orderedDate" : "2014-11-09T11:33:02.823",
  "items" : [ {
    "name" : "Java Chip"
  } ],
  "_links" : {
    "self" : {
      "href" : "http://localhost:8080/orders/1{?projection}",
      "templated" : true
    },
    "restbucks:items" : {
      "href" : "http://localhost:8080/orders/1/items"
    },
    "curies" : [ {
      "href" : "http://localhost:8080/alps/{rel}",
      "name" : "restbucks",
      "templated" : true
    } ]
  }
}

您正在运行DATAREST-394 ,它已经修复了几天,并且即将安装到2.2.2和2.3 RC1中。 所述版本的快照中已经提供了该功能,请随意试用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM