[英]Jaxb association of the same class
抱歉,標題不是很明確...在我的Projet模型中,我有一個Product
實體,該實體可以與其他產品關聯,但是我不知道如何對其進行注釋。 目前,我已經做到了:
@XmlRootElement(name = "product")
@XmlType(propOrder = { "barCode", "productName", "price", "brand", "description", "reviews", "photos", "videos", "associated" })
@XmlAccessorType(XmlAccessType.FIELD)
public class Product {
@XmlAttribute(name = "id")
private Long productId;
private String barCode;
private String productName;
private Double price;
@XmlElementWrapper(name = "photos")
@XmlElement(name = "photo", type = String.class)
private List<String> photos;
@XmlElementWrapper(name = "videos")
@XmlElement(name = "video", type = String.class)
private List<String> videos;
private String brand;
private String description;
@XmlElementWrapper(name = "reviews")
@XmlElement(name = "review", type = Review.class)
private List<Review> reviews;
@XmlElementWrapper(name = "associated")
@XmlElement(name = "product", type = Product.class)
private List<Product> associated;
// with constructor, getters and setters not annotated
}
當前,由於循環引用,此映射不起作用。 我想要一些類似的東西:
<product id="1">
<barCode>123456789</barCode>
<productName>Product 1</productName>
<price>100.0</price>
<brand>Brand 1</brand>
<description>Description 1</description>
<reviews/>
<photos/>
<videos/>
<associated>
<product id="2">
<barCode>987654321</barCode>
<productName>Product 2</productName>
<price>500.0</price>
<brand>Brand 2</brand>
<description>Description 2</description>
</product>
</associated>
</product>
我的意思是在地圖中沒有photos
, videos
, reviews
和associated
,這可能嗎? 我希望我已經足夠清楚了,如果不僅僅是問我,我會詳細解釋!
如果要排除映射的字段,請使用@XmlTransient(適用於處理循環引用)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.