使用JAXB处理JavaBean和XML的转换
package com.jadyer.jaxb;import javax.xml.bind.annotation.XmlRootElement;/** * 必须显式或隐式的提供默认的构造方法 */@XmlRootElementpublic class Student {private int id; //学生编号private int age; //学生年龄private String name; //学生姓名private Classroom classroom; //学生所属班级public Student() {}public Student(int id, int age, String name, Classroom classroom) {this.id = id;this.age = age;this.name = name;this.classroom = classroom;}}/** * 各属性的getter和setter方法略 */public class Classroom {private int id; //班级编号private int grade; //班级年级private String name; //班级名称public Classroom() {}public Classroom(int id, int grade, String name) {this.id = id;this.grade = grade;this.name = name;}}