我有一个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;
}
.....
 }

错误是



感谢您的光临!

最佳答案

从JavaDoc中获取@XmlType:

您需要将CustomerFullAddress属性添加到propOrderCustomer中。

关于java - 2个非法注释异常(exception)计数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10094622/

10-09 00:13