锁定老帖子 主题:请介绍一个xml,bean互转
精华帖 (0) :: 良好帖 (2) :: 新手帖 (0) :: 隐藏帖 (4)
|
|
---|---|
作者 | 正文 |
发表时间:2011-08-22
jaxb还不错,封装一个util,用起来还算舒心
|
|
返回顶楼 | |
发表时间:2011-08-22
直接上网址
http://www.castor.org/xml-framework.html |
|
返回顶楼 | |
发表时间:2011-08-22
json
|
|
返回顶楼 | |
发表时间:2011-08-22
cn-done 写道
F.U.C.K 写道
详细内容请参考这里(这是一个更复杂一点的例子,HashMap类型互转,其中就有你需要的bean互转部分):http://www.chinasb.org/archives/2011/04/1556.shtml
package cn.com.farben.cms.app.stockline.util.adapter; import java.io.File; import java.util.LinkedHashMap; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; import cn.com.farben.cms.app.stockline.vo.StockLineVO; import cn.com.farben.cms.app.stockline.vo.StockVO; public class Test { public static void main(String[] args) throws JAXBException { JAXBContext jaxbContext = JAXBContext.newInstance(StockLineVO.class); StockLineVO stockLineVO = new StockLineVO(); stockLineVO.setStockName("新华制药"); stockLineVO.setStockCode("000756"); LinkedHashMap<String, StockVO> stockLinkedHashMap = new LinkedHashMap<String, StockVO>(); stockLinkedHashMap.put("2007010225", new StockVO("2007010225","10.0","10.1","10.2","10.3","10.4","10.5")); stockLinkedHashMap.put("2007010226", new StockVO("2007010226","10.0","10.1","10.2","10.3","10.4","10.5")); stockLinkedHashMap.put("2007010224", new StockVO("2007010226","10.0","10.1","10.2","10.3","10.4","10.5")); stockLineVO.setStockLinkedHashMap(stockLinkedHashMap); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); // Output the generated XML: marshaller.marshal(stockLineVO, System.out); // Save the output to a foo.xml File xmlFile = new File("d:\\stock.xml"); marshaller.marshal(stockLineVO, xmlFile); // Restore the Foo class from xml file Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); StockLineVO _stockLineVO = (StockLineVO) unmarshaller.unmarshal(xmlFile); // See the result System.out.println(_stockLineVO.getStockLinkedHashMap().get("2007010224").getDate()); } }最近用了xstream 性能确实不咋滴,试试这个先 我想知道 怎么样才能测试XStream 性能不好?我比较关注怎么去测试,刚好这两天碰到这个东西,感觉用起来还是挺简单的,性能不知道怎么测试 和评估!!!
哪位能给出点可行性的意见和建议??? |
|
返回顶楼 | |
发表时间:2011-08-23
学习了,原来有这么多
|
|
返回顶楼 | |
发表时间:2011-09-29
谢谢各位~最后决定使用JAXB,项目告一段落,总结一下学习笔记,请参看
http://kamuikyo.iteye.com/blog/1182266 http://kamuikyo.iteye.com/blog/1182285 http://kamuikyo.iteye.com/blog/1182292 http://kamuikyo.iteye.com/blog/1182306 http://kamuikyo.iteye.com/blog/1182312 http://kamuikyo.iteye.com/blog/1182316 |
|
返回顶楼 | |
发表时间:2011-09-29
我用的是castor,固定报文是自己写的一个函数,看博客吧
http://mikewanghaiteng.iteye.com/admin/blogs/1171392 |
|
返回顶楼 | |