spring-data-rest,您能否提供实体的完整详细信息而不是(或带有)链接 [英] spring-data-rest, can you provide full details of entity instead of (or with) link
问题描述
有没有办法返回加入实体的完整详细信息而不是链接?在下面的示例中,我还想返回产品的详细信息,如果我有 100 次购买的列表,则可以避免必须拨打 100 次电话才能获取产品详细信息.
Is there a way to return the full details of a joined entity instead of a link? In the example below I want to also return the details of the product, if I have list of 100 purchases, it would avoid having to make 100 calls to get the product details.
Product、User 和 Purchase 实体的存储库都是使用 spring-data-jpa 创建的
The repositories for Product, User and Purchase entities are all created using spring-data-jpa
{
"_embedded" : {
"purchase" : [ {
"_links" : {
"product" : {
"href" : "http://localhost:8080/webapp/purchase/1/product"
},
"user" : {
"href" : "http://localhost:8080/webapp/purchase/1/user"
}
},
"purchasedOn" : "2014-02-23",
"amount" : 1
} ]
}
}
实体和存储库;
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, targetEntity = Purchase.class, orphanRemoval = true)
@JoinColumn(name = "user_id", updatable = false)
private List<Purchase> purchases = new ArrayList<>();
}
@Entity
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
}
@Entity
public class Purchase implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id;
@ManyToOne
@JoinColumn(name = "user_id", referencedColumnName = "id")
private User user;
@ManyToOne(fetch = FetchType.EAGER, targetEntity = Product.class)
@JoinColumn(name = "product_id", referencedColumnName = "id")
private Product product;
@Column(name = "purchase_date")
private Date purchaseDate;
private Integer amount;
}
@Repository
public interface PurchaseRepository extends JpaRepository<Purchase, Long> {}
推荐答案
似乎已经有针对此功能的新功能请求;
It would seems there is already a New Feature request for this functionality;
https://jira.springsource.org/browse/DATAREST-221
https://jira.springsource.org/browse/DATAREST-243
在该功能实现之前,我会一直悬而未决.
I'll leave the question open until the feature has been implemented.
这篇关于spring-data-rest,您能否提供实体的完整详细信息而不是(或带有)链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!