我认为这应该很容易,但我真的做不到。
我从 WebMethod 返回一个 Pojo:
@WebMethod
public SubCategoria getSubCategorias() throws JAXBException {
SubCategoria a = subCategoriaEJB.getAllSubCategorias().get(1);
return a;
}
我只是返回第一个,尝试一下。
我正在使用 soapUI 来测试我的 Ws。
响应是:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getSubCategoriasResponse xmlns:ns2="http://webService/">
<return>
<categoria>
<descripcion>Categoria Unica</descripcion>
<idCategoria>1</idCategoria>
</categoria>
<descripcion>asd123213</descripcion>
<idSubCategoria>2</idSubCategoria>
</return>
</ns2:getSubCategoriasResponse>
</S:Body>
</S:Envelope>
我希望将“返回”节点称为“SubCategoria”。我真的不能让它与 XmlRootElement 注释一起工作。
这是我的 Pojo(子类别)
package ejb.Entidades;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.xml.bind.annotation.XmlRootElement;
@Entity
@XmlRootElement(name="SubCategoria")
public class SubCategoria {
@Id
private Integer idSubCategoria;
@ManyToOne
private Categoria categoria;
private String descripcion;
public Integer getIdSubCategoria() {
return idSubCategoria;
}
public void setIdSubCategoria(Integer idSubCategoria) {
this.idSubCategoria = idSubCategoria;
}
public String getDescripcion() {
return descripcion;
}
public void setDescripcion(String descripcion) {
this.descripcion = descripcion;
}
public Categoria getCategoria() {
return categoria;
}
public void setCategoria(Categoria categoria) {
this.categoria = categoria;
}
}
有人知道吗?
提前致谢。
最佳答案
你应该使用@WebResult
注解:
@WebMethod
@WebResult(name = "subCategoria")
public SubCategoria getSubCategorias() throws JAXBException {
SubCategoria a = subCategoriaEJB.getAllSubCategorias().get(1);
return a;
}
关于web-services - 返回 Pojo WebService JaxWS。重命名 <return> 节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12169350/