对不起,标题不是很明确......在我的项目模型中,我有一个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
,是否可能?
我希望我很清楚,如果不是问,我会详细解释一下!
答案 0 :(得分:0)
如果要排除映射字段,请使用@XmlTransient(适用于处理循环引用)