【问题标题】:Generate list tag and object tag in jaxb在jaxb中生成列表标签和对象标签
【发布时间】:2013-04-23 10:39:32
【问题描述】:

我想在 jaxb 中生成列表标签和对象标签。 我有两节课。

@XmlRootElement(name = "firstclass")
    class Firstclass{
     List<secondclass> secondclassList = new ArrayList<secondclass>();

     //constructors, getters, setters

      @XmlElement(name = "secondclassList")
       public void setsecondclassList(List<Secondclass> secondclassList) {
       this.secondclassList= secondclassList;
      }

    }

二等代码

@XmlRootElement(name = "secondclass")
    class Secondclass{
     String name;
     String attribute;

     //constructors, getters, setters
    }

xml 转换后,我得到像这样的输出

<firstclass>
    <secondclassList>
      <name>my name</name>
      <attribute>attr value 11</attribute>
    <secondclassList>
    </secondclassList>
      <name>my name</name>
      <attribute>attr value 22</attribute>
    </secondclassList>
</firstclass>

但我想要这样的输出

<firstclass>
    <secondclassList>
         <secondclass>
              <name>my name</name>
              <attribute>attr value 11</attribute>
         </secondclass>
         <secondclass>
              <name>my name</name>
              <attribute>attr value 22</attribute>
         </secondclass>
     </secondclassList>
</firstclass>

【问题讨论】:

    标签: java xml tags jaxb


    【解决方案1】:

    尝试使用:

      @XmlElementWrapper(name = "secondclassList")
      @XmlElement(name="secondclass")
      public void setsecondclassList(List<Secondclass> secondclassList) {
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-02-18
      • 1970-01-01
      • 1970-01-01
      • 2014-02-22
      • 1970-01-01
      • 2017-11-06
      • 1970-01-01
      相关资源
      最近更新 更多