如何在JAXB中将Java集合转换为XMLElement的属性?

如何在JAXB中将Java集合转换为XMLElement的属性?,java,xml,jaxb,Java,Xml,Jaxb,我有以下两门课。一个包含另一个的数组 @XmlType(name="category", propOrder = { "title", "description", "sdImg", "hdImg","categoryLeafDTO" } ) public class CategoryDTO implements Serializable { @XmlElementWrapper (name="categoryleaf") public CategoryLea

我有以下两门课。一个包含另一个的数组

@XmlType(name="category", propOrder =          { "title", "description", "sdImg", "hdImg","categoryLeafDTO" } ) 
public class CategoryDTO implements Serializable {
    @XmlElementWrapper (name="categoryleaf")
    public CategoryLeafDTO[] getCategoryLeafDTO() {
        return this.categoryleafdto;
    }

    public void setCategoryLeafDTO(CategoryLeafDTO[] categoryleafdto) {
       this.categoryleafdto = categoryleafdto;
    }
}

当我变换时,它显示为

<category title="Trailers" description="Just Trailers"     sd_img="http://a.dolimg.com/media/en-US/m/dcom/tvapp/roku/assets/trailers_v4e_250.png"    hd_img="http://a.dolimg.com/media/en-US/m/dcom/tvapp/roku/assets/trailers_v4e_250.png">
   <categoryleaf>
      <categoryLeafDTO title="Trailers" description="Just Trailers" autoplay="ON" /> 
      <categoryLeafDTO title="Cars" description="cars the movie" autoplay="OFF" /> 
   </categoryleaf>
</category>

但我的要求是把它作为

<category title="Trailers" description="Just Trailers"  sd_img="http://a.dolimg.com/media/en-US/m/dcom/tvapp/roku/assets/trailers_v4e_250.png"  hd_img="http://a.dolimg.com/media/en-US/m/dcom/tvapp/roku/assets/trailers_v4e_250.png">
   <categoryleaf title="Trailers" description="Just Trailers" autoplay="ON">
   <categoryleaf title="Cars" description="cars the movie" autoplay="OFF">
</category>

类别中,将
@xmlementwrapper
替换为
@xmlement
,即

@XmlElement(name="categoryleaf")
public CategoryLeafDTO[] getCategoryLeafDTO() {
    return this.categoryleafdto;
}

@xmlementwrapper
用于希望集合周围有包装元素的情况。

类别中,将
@xmlementwrapper
替换为
@xmlementwrapper
,即

@XmlElement(name="categoryleaf")
public CategoryLeafDTO[] getCategoryLeafDTO() {
    return this.categoryleafdto;
}
@xmlementwrapper
用于希望集合周围有包装器元素的情况