使用Spring RestTemplate,如何将以下XML结果映射到某个域对象? 作为一个解决方案,我设计了以下Domain类,但我很想知道如何将这些包含值(例如:100,200,300)映射到域对象属性。 谢谢。
XML结果
<counting>
<value id="1" name="Robin" date="2015-09-03">100</value>
<value id="2" name="Joy" date="2015-09-03">200</value>
<value id="3" name="Tan" date="2015-09-03">300</value>
<counting>
域类
@XmlRootElement(name = "counting")
public class Count {
private Value value;
public Count() {}
// Getters and setters
}
@XmlRootElement(name = "value")
public class Value {
public Value() {}
private long id;
private String name;
private Date date;
// Getters and setters
}
答案 0 :(得分:0)
我用以下数据模型解决了这个问题
@XmlRootElement(name = "counting")
public class Count {
private List<Value> value;
public Count() {}
// Getters and setters
@XmlElement
public List<Value> getValue() {
return value;
}
public void setValue(List<Value> value) {
return this.value = value;
}
}
@XmlAccessorType(XmlAccessorType.FIELD)
public class Value {
public Value() {}
@XmlAttribute
private long id;
@XmlAttribute
private String name;
@XmlAttribute
private String date;
@XmlValue
private String xmlValue;
// Getters and setters
}