@Test public void xmlToObject()throws Exception { JaxbSample.objectToXml(); User u = JaxbSample.xmlToObject(); assertNotNull(u); assertEquals("jaxb", u.getUserName()); for (LoginLog log : u.getLogs().getLoginLog()) { assertNotNull(log); assertNotNull(log.getIp()); assertNotNull(log.getLoginDate()); } }
public static User xmlToObject() throws Exception { JAXBContext context = JAXBContext.newInstance(User.class); FileReader reader = new FileReader("out/JaxbSample.xml"); Unmarshaller um = context.createUnmarshaller(); User u = (User) um.unmarshal(reader); for (LoginLog log : u.getLogs().getLoginLog()) { if (log != null) { System.out.println("访问IP: " + log.getIp()); System.out.println("访问时间: " + log.getLoginDate().getTime()); } } return u; }
JaxbSample { public static User xmlToObject() throws Exception { JAXBContext context = JAXBContext.newInstance(User.class); FileReader reader = new FileReader("out/JaxbSample.xml"); Unmarshaller um = context.createUnmarshaller(); User u = (User) um.unmarshal(reader); for (LoginLog log : u.getLogs().getLoginLog()) { if (log != null) { System.out.println("访问IP: " + log.getIp()); System.out.println("访问时间: " + log.getLoginDate().getTime()); } } return u; } }
JaxbSample { public static User xmlToObject() throws Exception { JAXBContext context = JAXBContext.newInstance(User.class); FileReader reader = new FileReader("out/JaxbSample.xml"); Unmarshaller um = context.createUnmarshaller(); User u = (User) um.unmarshal(reader); for (LoginLog log : u.getLogs().getLoginLog()) { if (log != null) { System.out.println("访问IP: " + log.getIp()); System.out.println("访问时间: " + log.getLoginDate().getTime()); } } return u; }  }
JaxbSample { public static User xmlToObject() throws Exception { JAXBContext context = JAXBContext.newInstance(User.class); FileReader reader = new FileReader("out/JaxbSample.xml"); Unmarshaller um = context.createUnmarshaller(); User u = (User) um.unmarshal(reader); for (LoginLog log : u.getLogs().getLoginLog()) { if (log != null) { System.out.println("访问IP: " + log.getIp()); System.out.println("访问时间: " + log.getLoginDate().getTime()); } } return u; }  static User getUser(); static void objectToXml(); static User xmlToObject(); static void main(String args[]); }
JaxbSample { public static User xmlToObject() throws Exception { JAXBContext context = JAXBContext.newInstance(User.class); FileReader reader = new FileReader("out/JaxbSample.xml"); Unmarshaller um = context.createUnmarshaller(); User u = (User) um.unmarshal(reader); for (LoginLog log : u.getLogs().getLoginLog()) { if (log != null) { System.out.println("访问IP: " + log.getIp()); System.out.println("访问时间: " + log.getLoginDate().getTime()); } } return u; }  static User getUser(); static void objectToXml(); static User xmlToObject(); static void main(String args[]);  }