zoukankan      html  css  js  c++  java
  • 写了个JAVA对象到XML的转换工具,很简单但很实用,邀有兴趣来提交代码

    比起其它的优势在于代码少,不依赖任何JAR包, 可以用 SAX生成,这样可以支持大数据XML生成了(现在用标准的DOM) ,

    用空的可以提交到branch dev 

    DTO2XML
    =======
    
    use annotation let a Data Transfer Object(DTO) as a XML
    
    
    this is first vision
    
    example. 
    
    
    import org.dtotxml.annotation.tag.XMLFiled;
    
    /**
     * @author jinbinHe
     * this is a Data Transfer Object(DTO)
     */
    public class Message {
      @XMLFiled(fildName="newMessage")
    	public String dataName;
    	@XMLFiled(fildName="qvodzy") //fildName就是XML里面的element名字
    	public String title;//值就是显示在XML里两元素之间的值
    	@XMLFiled(fildName="qvodzy",attributeName="NAME")//attributeName就是属性名称,对应的fieldname
    	public String name;//对应属性值
    	@XMLFiled(fildName="qvodzy",attributeName="ADRESS")
    	public String adreess;
    	@XMLFiled(fildName="qvodzy",attributeName="DESCRIPTION")
    	public String description;
    	public String getTitle() {
    		return title;
    	}
    
    	public void setTitle(String title) {
    		this.title = title;
    	}
    	public String getName() {
    		return name;
    	}
    
    	public void setName(String name) {
    		this.name = name;
    	}
    
    	public String getAdreess() {
    		return adreess;
    	}
    
    	public void setAdreess(String adreess) {
    		this.adreess = adreess;
    	}
    
    	public String getDescription() {
    		return description;
    	}
    
    	public void setDescription(String description) {
    		this.description = description;
    	}
    	public String getDataName() {
    		return dataName;
    	}
    
    	public void setDataName(String dataName) {
    		this.dataName = dataName;
    	}
    
    
    }
    
    
    //so you can use DTO2XML like this . let it be a xml format
    
      @Test
    	public void testThisGuy() throws IllegalArgumentException,
    			IllegalAccessException, ParserConfigurationException, TransformerFactoryConfigurationError, TransformerException {
    		Message message = new Message();
    		message.setDataName("http://www.qvodzy.cc");
    		message.setTitle("qvod source web");
    		message.setName("qvod");
    		message.setAdreess("qvodzy.cc");
    		message.setDescription("this is a firm web");
    		System.out.println(new XMLOutPutByDTO().XMLOutPutByBean(message));
    	}
    
    //run test unit .you can get a String format as xml like below
    
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <message>
    <qvodzy ADRESS="qvodzy.cc" DESCRIPTION="this is a firm web" NAME="qvod">qvod source web</qvodzy>
    <newMessage>http://www.qvodzy.cc</newMessage>
    </message>
    
    //the Advantage is small and without any another lib,
    //in the next vision. I will add SAX to format xml to support big data 
    
    //have  any question please send email for me. qing878@gmail.com
    //QQ 277803242 HeJinBin
    // 源码地址 https://github.com/bensonHe/DTO2XML

     源码地址: https://github.com/bensonHe/DTO2XML

    抽空我在弄成JAR包

  • 相关阅读:
    React源码 Suspense 和 ReactLazy
    React源码 ReactContext
    BZOJ 3456: 城市规划 与 多项式求逆算法介绍(多项式求逆, dp)
    LOJ #6436. 「PKUSC2018」神仙的游戏(字符串+NTT)
    LOJ #6433. 「PKUSC2018」最大前缀和(状压dp)
    LOJ #6432. 「PKUSC2018」真实排名(组合数)
    LOJ #2542. 「PKUWC 2018」随机游走(最值反演 + 树上期望dp + FMT)
    LOJ #2541. 「PKUWC 2018」猎人杀(容斥 , 期望dp , NTT优化)
    LOJ #2540. 「PKUWC 2018」随机算法(概率dp)
    LOJ #2538. 「PKUWC 2018」Slay the Spire (期望dp)
  • 原文地址:https://www.cnblogs.com/springsource/p/2947738.html
Copyright © 2011-2022 走看看