我认为唯一的方法是创建 2 个新类“OddSettings”和“EvenSettings”,并将“OddEvenSettings”引用到“OddSettings”和“EvenSettings”,如下所示:
@XmlRootElement(name="OddEvenSettings")
public class OddEvenSettings {
@XmlElement(name="odd")
private OddSetting oddSetting = new OddSetting();
@XmlElement(name="even")
private EvenSetting evenSetting = new EvenSetting();
...
}
当然OddSettings
,EvenSettings
也应该注释:
@XmlAccessorType(XmlAccessType.FIELD)
public class OddSetting {
@XmlAttribute(name="setting1")
int oddSetting1;
@XmlAttribute(name="setting2")
int oddSetting2;
...
}
@XmlAccessorType(XmlAccessType.FIELD)
public class EvenSetting {
@XmlAttribute(name="setting1")
int evenSetting1;
@XmlAttribute(name="setting2")
int evenSetting2;
...
}
这会产生你需要的东西:
<OddEvenSettings>
<odd setting1="0" setting2="0"/>
<even setting1="0" setting2="0"/>
</OddEvenSettings>