<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<staffs>
<records xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="employee">
<id>1</id>
<name>Danial</name>
<age>20</age>
<TFN>1231231</TFN>
<contact>12314123</contact>
<jobType>WAITER</jobType>
<wage>12.0</wage>
</records>
<records xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="employee">
<id>2</id>
<name>Andrew</name>
<age>21</age>
<TFN>1231254</TFN>
<contact>123677</contact>
<jobType>ADMIN</jobType>
<wage>18.0</wage>
</records>
<records xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="employee">
<id>3</id>
<name>Jenny</name>
<age>19</age>
<TFN>1231432</TFN>
<contact>1239873</contact>
<jobType>WAITRESS</jobType>
<wage>15.0</wage>
</records>
<employees>
<id>1</id>
<name>Danial</name>
<age>20</age>
<TFN>1231231</TFN>
<contact>12314123</contact>
<jobType>WAITER</jobType>
<wage>12.0</wage>
</employees>
<employees>
<id>2</id>
<name>Andrew</name>
<age>21</age>
<TFN>1231254</TFN>
<contact>123677</contact>
<jobType>ADMIN</jobType>
<wage>18.0</wage>
</employees>
<employees>
<id>3</id>
<name>Jenny</name>
<age>19</age>
<TFN>1231432</TFN>
<contact>1239873</contact>
<jobType>WAITRESS</jobType>
<wage>15.0</wage>
</employees>
</staffs>
无论如何使用jaxb之后我的输出就是上面的。 这是正常的??为什么要重复输入? 记录保存LinkedList和Employees扩展记录
如果离开以防止这种情况,那就很想听到
import javax.xml.bind.annotation.*;
@XmlRootElement(name = "staffs")
@XmlAccessorType(XmlAccessType.FIELD)
public class Employees extends Records
{
@XmlElement(type = Employee.class)
public LinkedList<Record> getEmployees()
{
return super.getRecords();
}
}
//////////////////////Employee class/////////////////
import javax.xml.bind.annotation.*;
@XmlRootElement(name = "staff")
@XmlAccessorType(XmlAccessType.FIELD)
public class Employee extends Record
{
}
答案 0 :(得分:1)
问题在于你必须得到实际返回相同列表的getter:
见
public LinkedList<Record> getEmployees()
{
return super.getRecords();
}
这就是为什么你有这两个几乎相同的列表。你真的需要这个重复的吸气剂吗?如果没有,只需删除它,输出就没有重复项。