我正在使用 Java/Eclipse/Spring 创建 Web 服务。我正在编写一个 XSD 文件,其中包含用于 Web 服务(请求、响应等)的 Java 类的结构。我在 XSD 文件上使用“生成 Jaxb 类”选项来创建 Java 类。它适用于 int、string、long 等数据类型,但是,当我的属性是对象的 ArrayList 时,生成的 Java 类没有该属性的“SET”方法。它只有“GET”方法。
这是一个例子:
XSD 文件:
<element name="GetPrizesAndCatalogsResponse">
<complexType>
<sequence>
<element name="answerCode" type="int" />
<element name="prizes" type="tns:SW_Prize" maxOccurs="unbounded"></element>
<element name="prizesCatalog" type="tns:SW_Catalog" maxOccurs="unbounded"></element>
<element name="pagination" type="tns:SW_Pagination"></element>
</sequence>
</complexType>
</element>
Java类:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"answerCode",
"prizes",
"prizesCatalog",
"pagination"
})
@XmlRootElement(name = "GetPrizesAndCatalogsResponse")
public class GetPrizesAndCatalogsResponse {
protected int answerCode;
@XmlElement(required = true)
protected List<SWPrize> prizes;
@XmlElement(required = true)
protected List<SWCatalog> prizesCatalog;
@XmlElement(required = true)
protected SWPagination pagination;
/**
* Obtiene el valor de la propiedad answerCode.
*
*/
public int getAnswerCode() {
return answerCode;
}
/**
* Define el valor de la propiedad answerCode.
*
*/
public void setAnswerCode(int value) {
this.answerCode = value;
}
/**
* Gets the value of the prizes 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 prizes property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getPrizes().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link SWPrize }
*
*
*/
public List<SWPrize> getPrizes() {
if (prizes == null) {
prizes = new ArrayList<SWPrize>();
}
return this.prizes;
}
/**
* Gets the value of the prizesCatalog 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 prizesCatalog property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getPrizesCatalog().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link SWCatalog }
*
*
*/
public List<SWCatalog> getPrizesCatalog() {
if (prizesCatalog == null) {
prizesCatalog = new ArrayList<SWCatalog>();
}
return this.prizesCatalog;
}
/**
* Obtiene el valor de la propiedad pagination.
*
* @return
* possible object is
* {@link SWPagination }
*
*/
public SWPagination getPagination() {
return pagination;
}
/**
* Define el valor de la propiedad pagination.
*
* @param value
* allowed object is
* {@link SWPagination }
*
*/
public void setPagination(SWPagination value) {
this.pagination = value;
}
}
我对 XSD 文件的定义是否正确?是否有必要在 XML 上添加另一个标签?