xml转Bean JAXBContext context = JAXBContext.newInstance(Bean.class); Unmarshaller unmarshaller = context.createUnmarshaller(); Bean bean = (Bean) unmarshaller.unmarshal(new StringReader(xml)); Bean转Xml JAXBContext context = JAXBContext.newInstance(Bean.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,true); StringWriter writer = new StringWriter(); marshaller.marshal(bean,writer);
原文链接:https://www.f2er.com/xml/294368.html