如何为SOAP请求中的属性设置注释? 我的例子:
public class Example {
@WebMethod()
public void test(@WebParam(name="pingRequest")PingRequest HotelPingRQ) {}
}
public class PingRequest
{
private String echo;
public String getEcho() {
return echo;
}
public void setEcho(String echo) {
this.echo = echo;
}
}
如果我生成一个WSDL并将其放入SoapUI中,我会得到:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:door="http://www.test.com/doorway">
<soapenv:Header/>
<soapenv:Body>
<door:test>
<pingRequest>
<!--Optional:-->
<echo>?</echo>
</pingRequest>
</door:test>
</soapenv:Body>
但我希望更像以下内容,echo
作为属性而没有测试元素:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:door="http://www.test.com/doorway">
<soapenv:Header/>
<soapenv:Body>
<pingRequest echo="?" />
</soapenv:Body>
如何将echo
参数转换为pingRequest
上的属性而不是嵌套元素?
答案 0 :(得分:1)
试试这个:
@XmlAccessorType(XmlAccessType.FIELD)
public class PingRequest
{
@XmlAttribute
private String echo;
public String getEcho() {
return echo;
}
public void setEcho(String echo) {
this.echo = echo;
}
}