我有一个 Customer 和 CustomerFullAddress 类,我正在使用 JAXB 尝试生成 XML 文件
<Customer CustomerID="GREAL">
<CompanyName>Great Lakes Food Market</CompanyName>
<ContactName>Howard Snyder</ContactName>
<ContactTitle>Marketing Manager</ContactTitle>
<Phone>(503) 555-7555</Phone>
<FullAddress>
<Address>2732 Baker Blvd.</Address>
<City>Eugene</City>
<Region>OR</Region>
<PostalCode>97403</PostalCode>
<Country>USA</Country>
</FullAddress>
</Customer>
客户类如下所示(它不是一个完整的实现)
package org.abc.customers;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
@XmlRootElement(name = "customer")
@XmlType (propOrder = { "companyName", "contactName", "contactTitle", "phone" })
public class Customer {
*@XmlElement(name = "customerfulladdress")
private CustomerFullAddress custAdd;*
private String companyName;
private String contactName;
private String contactTitle;
private int phone;
public CustomerFullAddress getCustAddress() {
return custAdd;
}
public void setCustAddress(CustomerFullAddress custAdd) {
this.custAdd = custAdd;
}
...
而 CustomerFullAddress 是
package org.abc.customers;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
@XmlRootElement(name = "customerfulladdress")
//If you want you can define the order in which the fields are written
//Optional
@XmlType(propOrder = { "address", "city", "region", "postalCode", "country" })
public class CustomerFullAddress {
private String address;
...
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
.....
}
错误是
线程“主”com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException 中的异常:2 计数 IllegalAnnotationExceptions 属性 custAdd 存在但未在 @XmlType.propOrder 中指定此问题与以下位置有关:在私有组织.abc.customers.CustomerFullAddress org.abc.customers.Customer.custAdd at org.abc.customers.Customer 属性 custAddress 存在但未在 @XmlType.propOrder 中指定此问题与以下位置有关:在公共 org.abc。 customers.CustomerFullAddress org.abc.customers.Customer.getCustAddress() 在 org.abc.customers.Customer
感谢您的关注!