【发布时间】:2021-08-25 19:13:35
【问题描述】:
我有两个类 ItemsDto 和 ItemDto 它们代表 XML 文件中的数据
@XmlR
ootElement(name = "items")
@XmlAccessorType(XmlAccessType.FIELD)
public class ItemsDto {
@XmlElementRef
private List<ItemDto> items;
public List<ItemDto> getItems() {
return items;
}
public void setItems(List<ItemDto> items) {
this.items = items;
}
}
还有一个
@XmlRootElement(name = "item")
@XmlAccessorType(XmlAccessType.FIELD)
public class ItemDto {
@XmlElement
private int itemNo;
@XmlElement
private String name;
@XmlElement
private String description;
@XmlElement
private int number;
@XmlElement
private int rating;
public ItemDto() {
}
public ItemDto(int itemNo, String name, String description, int number) {
this.itemNo = itemNo;
this.name = name;
this.description = description;
this.number = number;
}
//getters and setters
}
我有 test.xml 文件
<items>
<item>
<itemNo>998</itemNo>
<name>Rider Auto Part Generic Brakepad</name>
<description>Basic brakepad for any motorbike</description>
<number>100</number>
</item>
</items>
我想设置从文件读取的路径,但我不知道如何设置解组部分 我不知道该怎么办...
from("file:inputXML")
.unmarshal(). something
.process(exchange -> {
System.out.println(exchange.getIn().getBody());
})
【问题讨论】:
标签: xml routes apache-camel unmarshalling