gpt4 book ai didi

java - @XmlElementWrapper 用于使用 JAX-WS 的 Web 方法

转载 作者:行者123 更新时间:2023-11-30 09:44:31 24 4
gpt4 key购买 nike

我有一个如下所示的网络服务,它包含一个将返回对象列表的网络方法:

@WebService(name = "ClubMembershipPortType", serviceName = "ClubMembershipService", portName = "ClubMembershipSoapPort", targetNamespace = "http://club.com/api/ws")
public class ClubMembershipWS {
@WebMethod(operationName = "findClubMembershipsByClubId", action = "urn:findClubMembershipsByClubId")
@WebResult(name = "club_membership")
public List<ClubMembership> findClubMembershipsByClubId(@XmlElement(required=true)
@WebParam(name = "club_id") String clubId,
@WebParam(name = "status") StatusEnum status)
...
...
}
}

我得到的 api 请求响应如下:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:findClubMembersByClubIdResponse xmlns:ns2="http://club.com/api/ws">
<club_membership>
...
</club_membership>
<club_membership>
...
</club_membership>
</ns2:findClubMembersByClubIdResponse>
</S:Body>
</S:Envelope>

问题是如何使用@XmlElementWrapper(或其他方式?)做出如下响应?

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:findClubMembersByClubIdResponse xmlns:ns2="http://club.com/api/ws">
<club_membership_list>
<club_membership>
...
</club_membership>
<club_membership>
...
</club_membership>
</club_membership_list>
</ns2:findClubMembersByClubIdResponse>
</S:Body>
</S:Envelope>

最佳答案

你试过吗?

@XmlElementWrapper(name="club_membership_list", required=true)  
@XmlElement(name="club_membership", required=true)
public List<ClubMembership> findClubMembershipsByClubId(@WebParam(name = "club_id") String clubId,
@WebParam(name = "status") StatusEnum status)

关于java - @XmlElementWrapper 用于使用 JAX-WS 的 Web 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7870110/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com