gpt4 book ai didi

java - JAXB 解码 - Java 字段的 XML 属性

转载 作者:行者123 更新时间:2023-12-01 09:13:52 27 4
gpt4 key购买 nike

我正在尝试使用 JAXB 解码将以下 XML 转换为 Java 类,但我找不到将“zipCode”等 XML 属性转换为 java 字段“zipCode”的方法。我怎样才能在 JAXB 中实现这一目标?

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<datacollection id="amazonOrder">
<table name="AmazonOrderTable">
<row>
<field name="zipCode">20170</field>
<field name="customerLastName">DE</field>
<field name="state">VA</field>
<field name="city">COMMERCE CITY</field>
<field name="serialNumber">818243CX601252Y</field>
<field name="homePhone">3032885239</field>
<field name="customerFirstName">ROGER</field>
<field name="customerAddress">13390 E 106TH PL</field>
</row>
</table>
</datacollection>
public class CustomerInfo {

protected String customerAddress;
protected String customerFirstName;
protected String customerLastName;
protected String serialNumber;
protected String zipCode;
protected String city;

public String getCustomerAddress() {
return customerAddress;
}

public void setCustomerAddress(String customerAddress) {
this.customerAddress = customerAddress;
}

public String getCustomerFirstName() {
return customerFirstName;
}

public void setCustomerFirstName(String customerFirstName) {
this.customerFirstName = customerFirstName;
}

public String getCustomerLastName() {
return customerLastName;
}

public void setCustomerLastName(String customerLastName) {
this.customerLastName = customerLastName;
}

public String getSerialNumber() {
return serialNumber;
}

public void setSerialNumber(String serialNumber) {
this.serialNumber = serialNumber;
}

public String getZipCode() {
return zipCode;
}

public void setZipCode(String zipCode) {
this.zipCode = zipCode;
}

public String getCity() {
return city;
}

public void setCity(String city) {
this.city = city;
}
}

最佳答案

您可以尝试将 @XmlElement(name = "zipcode") 注释添加到 getZipCode()setZipCode() 方法中。

关于java - JAXB 解码 - Java 字段的 XML 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40726281/

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