我正在使用@XmlRootElement
注释以及@XmlElement
在我的 Spring MVC 应用程序中生成 xml 输出。我有以下课程:
@XmlRootElement
public class Chart
{
private String id;
private String name;
private List<Connection> connections;
//..................
@XmlElement(name = "connection")
public List<Connection> getConnections()
{
return this.connections;
}
//..................
}
public class Connection
{
private String from;
private String to;
public String getFrom()
{
return this.from;
}
public void setFrom(String from)
{
this.from = from;
}
public String getTo()
{
return this.to;
}
public void setTo(String to)
{
this.to = to;
}
}
我得到这样的 xml 输出:
<chart>
<id>a1</id>
<name>chart1</name>
<connection>
<from>a1</from>
<to>a2</to>
</connection>
....
</chart>
但是,我需要以这种方式格式化 xml:
<chart>
<id>a1</id>
<name>chart1</name>
<connection from="a1" to="a2"></connection>
....
</chart>
如何配置注释以实现此结果?