Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用JAXB为列表生成Setter_Java_Jaxb - Fatal编程技术网

Java 使用JAXB为列表生成Setter

Java 使用JAXB为列表生成Setter,java,jaxb,Java,Jaxb,我使用JAXB将XML配置映射到Java对象。可以从UI编辑此配置,这就是为什么要将其传输到UI,反之亦然。我肯定需要将json解压到Java对象中。因此,需要为列表设置setter方法 如何使用JAXB为POJO类的List属性生成setter方法?为此,您需要创建List变量。此List变量的setter-getter方法如下所示 package foo.bar.me.too; import java.util.List; import javax.xml.bind.annotation

我使用
JAXB
XML
配置映射到Java对象。可以从
UI
编辑此配置,这就是为什么要将其传输到UI,反之亦然。我肯定需要将
json
解压到Java对象中。因此,需要为
列表
设置setter方法


如何使用JAXB为POJO类的List属性生成setter方法?

为此,您需要创建List变量。此List变量的setter-getter方法如下所示

package foo.bar.me.too;

import java.util.List;

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

@XmlRootElement(name="VisitorDataList")
public class visitordatalist {


    List<visitordata> vstd;

    @XmlElement(name="VisitorData")
    public List<visitordata> getVstd() {
        return vstd;
    }

    public void setVstd(List<visitordata> vstd) {
        this.vstd = vstd;
    }   

}
package foo.bar.me.too;
导入java.util.List;
导入javax.xml.bind.annotation.xmlement;
导入javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name=“VisitorDataList”)
公共类访问者数据列表{
列出vstd;
@XmlElement(name=“VisitorData”)
公共列表getVstd(){
返回vstd;
}
公共无效设置vstd(列表vstd){
this.vstd=vstd;
}   
}

出于安全原因,不会为列表对象生成setter

/**
 * Gets the value of the dateIntervals property.
 * 
 * <p>
 * This accessor method returns a reference to the live list,
 * not a snapshot. Therefore any modification you make to the
 * returned list will be present inside the JAXB object.
 * This is why there is not a <CODE>set</CODE> method for the dateIntervals property.
 * 
 * <p>
 * For example, to add a new item, do as follows:
 * <pre>
 *    getDateIntervals().add(newItem);
 * </pre>
 * 
 * 
 * <p>
 * Objects of the following type(s) are allowed in the list
 * {@link DateInterval }
 * 
 * 
 */
* * * *列表中允许以下类型的对象 *{@link DateInterval} * * */
我正在使用xjc生成类。使用自动生成的xjc类时是否有意义