尽量少使用jaxb 进行xml与对象互换
</jaxb:bingdings>
</jaxb:bindings>
?
write:
JAXBContext context = JAXBContent.newInstance(bean.getClass().getPackage().getName),Thread.currentThread().getContextClassLoader());
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,true);
marshaller.setProperty(Marshaller.JAXB_ENCODING,"UTF-8");
marshaller.setProperty(Marshaller.JAXB_FRAGMENT,false);
marshaller.marshal(bean,new File(filePath));
?
?
============================
read:
JAXBContext context = JAXBContent.newInstance(bean.getClass().getPackage().getName),Thread.currentThread().getContextClassLoader());
Unmarshaller unmarshaller = context.createUnmarshaller();
Object obj = unmarshaller.unmarshal(new File(filePath));
?
对于生成的JAXBElement对象实际过程中可将此对象替换为具体的类型的对象(String,Long,Boolean等)方便界面编辑保存。
?
?
?
?
?