日期:2014-05-20 浏览次数:20890 次
List<Book> books =new ArrayList<Book>(); Book book=new Book(); book.setName="书名1"; book.setContent="内容1"; Book book2=new Book(); book2.setName="书名2"; book2.setContent="内容2"; books.add(book); books.add(book2);
private String name; private String content; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getContent() { return content; } public void setContent(String content) { this.content = content; }
------解决方案--------------------
Book.java
@XmlType(propOrder={"name","content"}) @XmlRootElement(name="book") public class Book { private String name; private String content; @XmlElement public final String getContent() { return content; } public final void setContent(final String content) { this.content = content; } @XmlElement public final String getName() { return name; } public final void setName(final String name) { this.name = name; } }