我需要有一个VO,它将代表以下XML

<ROWSET>
<ROW>
  <ORDER_NUM>5101330188</ORDER_NUM>
  <LINE_NUM_SEQ>55</LINE_NUM_SEQ>
  <PROD_NUM_REQ>9BX134-505</PROD_NUM_REQ>
</ROW>
</ROWSET>


如何定义2个代表行集和行的xmlRootElements?我的VO是这样的:

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "ROWSET")
public class TestVo {

    String ORDER_NUM;
    String LINE_NUM_SEQ;
    String PROD_NUM_REQ;

    @XmlElement
    public String getLINE_NUM_SEQ() {
        return LINE_NUM_SEQ;
    }

    public void setLINE_NUM_SEQ(String lINE_NUM_SEQ) {
        LINE_NUM_SEQ = lINE_NUM_SEQ;
    }

    @XmlElement
    public String getORDER_NUM() {
        return ORDER_NUM;
    }

    public void setORDER_NUM(String oRDER_NUM) {
        ORDER_NUM = oRDER_NUM;
    }

    @XmlElement
    public String getPROD_NUM_REQ() {
        return PROD_NUM_REQ;
    }

    public void setPROD_NUM_REQ(String pROD_NUM_REQ) {
        PROD_NUM_REQ = pROD_NUM_REQ;
    }

}


我不能有2个XMLROOTELEMENTS,但是我需要定义<ROWSET><ROW>

最佳答案

唯一的解决方案是将@XmlRootElement(name = "ROWSET")更改为@XmlRootElement(name = "ROW")并发明这样的对象

@XmlRootElement(name="ROWSET")
public class Rowset{

    private List<TestVo> vos;
    [...]
}


因为XML不能有多个根。

关于java - 是否可以有多个xmlRootElements?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16337647/

10-10 02:32