zoukankan      html  css  js  c++  java
  • java JAXB @XmlAttribute @XmlElement @XmlValue实例

     实体类

    @Data
    public static class CouponOther{  
        private String type;
    
      
        private List<Ref> ref;
    
        @Data   
        public static class Ref{
    	
    	private String code;
    
    	
    	private String value;
        }
    
    }
    

      

    @XmlAttribute 用法

    @Data
    @XmlAccessorType(XmlAccessType.FIELD)
    public static class CouponOther{
        @XmlElement(name = "Type")
        private String type;
    
    }
    

    x效果:

      

    <Other>
          <Type>210</Type>      
    </Other>
    

      

    @XmlElement用法 :<Other Type="210"> </Other>

    @Data
    @XmlAccessorType(XmlAccessType.FIELD)
    public static class CouponOther{
        @XmlAttribute(name = "Type")
        private String type;
    
    }
    

      

    效果:

    <Other Type="210">  </Other>
    

      

    @XmlValue用法:<Ref Code="couponid">TEST071909</Ref>

    @Data
    @XmlAccessorType(XmlAccessType.FIELD)
    public static class CouponOther{
        @XmlAttribute(name = "Type")
        private String type;
    
        @XmlElement
        private List<Ref> ref;
    
        @Data
        @XmlAccessorType(XmlAccessType.FIELD)
        public static class Ref{
    	@XmlAttribute(name = "Code")
    	private String code;
    
    	@XmlValue
    	private String value;
        }
    
    }
    

      

    效果:

     <Other Type="210">
                        <Ref Code="OJ_SuperPNR_RPH">1</Ref>
                        <Ref Code="couponid">TEST071909</Ref>
                    </Other>
    

      

  • 相关阅读:
    面向 部分
    并发 编程
    数据库 部分
    匿名函数
    Linux 30岁,这些年经历了什么?
    漫谈 HTTP 连接
    华为交换机命令基础入门学习,小白也能看得懂!
    一文讲透APaaS平台是什么
    什么是边缘CDN和虚拟CDN (vCDN)?
    systemd进程管理工具实战教程
  • 原文地址:https://www.cnblogs.com/achengmu/p/15045198.html
Copyright © 2011-2022 走看看