gpt4 book ai didi

java - 2 次非法注解异常

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:16:32 24 4
gpt4 key购买 nike

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

错误是

Exception in thread "main" com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions Property custAdd is present but not specified in @XmlType.propOrder this problem is related to the following location: at private org.abc.customers.CustomerFullAddress org.abc.customers.Customer.custAdd at org.abc.customers.Customer Property custAddress is present but not specified in @XmlType.propOrder this problem is related to the following location: at public org.abc.customers.CustomerFullAddress org.abc.customers.Customer.getCustAddress() at org.abc.customers.Customer

感谢您的关注!

最佳答案

来自 @XmlType 的 JavaDoc :

propOrder

All of the JavaBean properties being mapped to XML Schema elements must be listed.

您需要将 CustomerFullAddress 属性添加到 CustomerpropOrder

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com