@XmlRootElement public class Book { private String title; private String author; @XmlElement public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } @XmlElement public String getAuthor() { return author; } public void setAuthor(String author) { this.author = author; } } public class JAXBExample { public static void main(String[] args) throws JAXBException { JAXBContext context = JAXBContext.newInstance(Book.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); Book book = new Book(); marshaller.marshal(book, System.out); } }


上一篇:
下一篇:
切换中文