我在尝试使用 JAXB2 注释呈现以下 xml 代码时遇到一些问题:
....
<bizTransactionList>
<bizTransaction type="urn:epcglobal:fmcg:btt:po">
http://transaction.acme.com/po/54847
</bizTransaction>
<!--other entries -->
</bizTransactionList>
...
按照文档,我设法解决了以下问题:1)在拥有列表的类中,我以这种方式注释列表吸气剂
@XmlElementWrapper(name="bizTransactionList")
@XmlElement(name="bizTransaction")
public List<BizTransaction> getBizTransactionList() {
return bizTransactionList;
}
2)我创建 BizTransaction 类如下
public class BizTransaction {
private URI transactionId;
private URI type;
@XmlValue
public URI getTransactionId() {
return transactionId;
}
public void setTransactionId(URI transactionId) {
this.transactionId = transactionId;
}
@XmlAttribute
public URI getType() {
return type;
}
public void setType(URI type) {
this.type = type;
}
public BizTransaction() {
// TODO Auto-generated constructor stub
}
public BizTransaction(URI transactionId, URI type) {
super();
this.transactionId = transactionId;
this.type = type;
}
}
现在的问题是该属性工作正常,但值(即 transactionId 变量)始终为空。你能帮我找出问题吗?