我正在尝试将具有表名、行数和列列表的表 bean 输出到 XML。如果我将它们注释为属性,它们会显示:所以这个定义:
@XmlRootElement(name = "table")
public class Table {
private String tableName;
private int rowCount;
private List<Column> columnList;
@XmlAttribute(name = "name")
public String getTableName() {
return tableName;
}
@XmlAttribute(name = "rowCount")
public int getRowCount() {
return rowCount;
}
@XmlElement(name = "column")
public List<Column> getColumnList() {
return columnList;
}
}
输出这个:
<tables>
<table name="GGS_MARKER" rowCount="19190">
<column>
<columnName>MARKER_TEXT</columnName>
<datatype>VARCHAR2</datatype>
<length>4000.0</length>
</column>
...
但是,如果我用@XmlElement 更改@XmlAttribute,它只会显示:
<tables>
<table>
<column>
<columnName>MARKER_TEXT</columnName>
<datatype>VARCHAR2</datatype>
<length>4000.0</length>
</column>
...
我应该在课堂上放什么来获得“名称”和“行数”作为元素?