Java 在JAXB中创建SOAP属性
我目前正在学习JAXB和Web服务,我有一个我不知道的问题 如何解决 假设我有一个用JAXB注释的非常简单的类Java 在JAXB中创建SOAP属性,java,web-services,soap,jaxb,jax-ws,Java,Web Services,Soap,Jaxb,Jax Ws,我目前正在学习JAXB和Web服务,我有一个我不知道的问题 如何解决 假设我有一个用JAXB注释的非常简单的类 @XmlRootElement public class Customer { private int custID; private String custName; //getters and setters } 我将这个类作为Web服务公开。(注意:为了简单起见,我在这里硬编码了所有内容。) 但这连接到数据库) SOAP信封响应如下所示 <S:En
@XmlRootElement
public class Customer {
private int custID;
private String custName;
//getters and setters
}
我将这个类作为Web服务公开。(注意:为了简单起见,我在这里硬编码了所有内容。)
但这连接到数据库)
SOAP信封响应如下所示
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:customerDataResponse xmlns:ns2="http://test.com/">
<return>
<custID>12345</custID>
<custName>John Doe</custName>
</return>
</ns2:customerDataResponse>
</S:Body>
</S:Envelope>
12345
无名氏
现在假设我在客户实体中有另一个名为status的属性,他们希望该属性作为soap的属性
响应如下,而不是客户元素的一部分。(A=活动,I=非活动)
12345
无名氏
@XmlRootElement
公共类客户{
私人帐户;
私有字符串名称;
//另一个注释??(仅限A或I)
私有字符串状态;
//接球手和接球手
}
如何注释类以满足此要求?谢谢Customer类上注释的所有内容都将与Customer元素相关
这是因为JAX-WS负责形成消息信封,然后JAXB将消息体封送到此信封中。到了JAXB整理正文的时候,更改信封已经太迟了。谢谢您的回复。是否有其他选择或解决办法,以便我可以做我想做的事?还有,有没有一种方法可以将任何属性硬编码到信封中,即使它不是任何实体的一部分(只是简单地硬编码任何实体…)?
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:customerDataResponse xmlns:ns2="http://test.com/">
<return>
<custID>12345</custID>
<custName>John Doe</custName>
</return>
</ns2:customerDataResponse>
</S:Body>
</S:Envelope>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:customerDataResponse status="A" xmlns:ns2="http://test.com/">
<return>
<custID>12345</custID>
<custName>John Doe</custName>
</return>
</ns2:customerDataResponse>
</S:Body>
</S:Envelope>
@XmlRootElement
public class Customer {
private int custID;
private String custName;
//Another Annotation??? (A or I only)
private String status;
//getters and setters
}