我正在研究SOAP WS,並且創建了一個非常簡單的 類,我將其公開爲Web服務。SOAP響應模式
@WebService
public class StudentWS {
@WebMethod
public Student getStudent(){
Student stud = new Student();
stud.setId(99);
stud.setFirstName("John");
stud.setLastName("Doe");
stud.setGpa(2.1);
return stud;
}
}
當我把這個Web服務,返回的SOAP響應如下 這種格式。
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getStudentResponse xmlns:ns2="http://annotation/">
<return>
<firstName>John</firstName>
<gpa>2.1</gpa>
<id>99</id>
<lastName>Doe</lastName>
</return>
</ns2:getStudentResponse>
</S:Body>
</S:Envelope>
我的問題是,是否有某種方式可以影響SOAP響應,以遵循如下所示的某種架構。
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getStudentResponse xmlns:ns2="http://annotation/">
<student gpa="2.1">
<id>99</id>
<name>
<firstName></firstName>
<lastName></lastName>
</name>
</student>
</ns2:getStudentResponse>
</S:Body>
</S:Envelope>
我的數據來自於像這樣的POJO類。
@XmlRootElement
public class Student {
private int id;
private String firstName;
private String lastName;
private double gpa;
//getters and setters
}
謝謝。