【发布时间】:2017-04-13 14:04:54
【问题描述】:
我正在尝试使用RepositoryRestResource 和RestTemplate 实现一个rest api
一切都很好,除了加载@DBRef's
考虑这个数据模型:
public class Order
{
@Id
String id;
@DBRef
Customer customer;
... other stuff
}
public class Customer
{
@Id
String id;
String name;
...
}
以及以下存储库(与客户类似)
@RepositoryRestResource(excerptProjection = OrderSummary.class)
public interface OrderRestRepository extends MongoRepositor<Order,String>{}
其余 api 返回以下 JSON:
{
"id" : 4,
**other stuff**,
"_links" : {
"self" : {
"href" : "http://localhost:12345/api/orders/4"
},
"customer" : {
"href" : "http://localhost:12345/api/orders/4/customer"
}
}
}
如果由 resttemplate 正确加载,它将创建一个新的 Order 实例,其中 customer = null
是否可以在存储库端急切地解析客户并嵌入JSON?
【问题讨论】:
标签: mongodb spring-boot spring-data-mongodb spring-data-rest