1. 编写简单的POJO,并添加基本的注解,类似于JPA,只有被@XmlRootElement标注的类才会处理:
package org.jack.jaxb;import javax.xml.bind.annotation.XmlRootElement;/** @author 李文锴*/@XmlRootElementpublic class Jack {private String firstName;private String lastName;public String getFirstName() {return firstName;}public void setFirstName(String firstName) {this.firstName = firstName;}public String getLastName() {return lastName;}public void setLastName(String lastName) {this.lastName = lastName;}}
2. 编写测试类,进行POJO与XML的转换:
3. 查看输出结果: