<student> <id>123</id> <age>20</age> </student> shell xjc student.xml import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; import javax.xml.bind.annotation.XmlRootElement; import java.io.File; @XmlRootElement class Student { private int id; private String name; private int age; public static void main(String[] args) { try { File file = new File("student.xml"); JAXBContext jaxbContext = JAXBContext.newInstance(Student.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); Student student = (Student) jaxbUnmarshaller.unmarshal(file); } catch (JAXBException e) { e.printStackTrace(); } } }


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