2016-04-08 93 views
2

我有一個web服務,它從數據庫中提取細節並返回到調用system.the特定標記的輸出可以有多個項目(父標記將有多個項目),而是它正在返回同樣的領域一次又一次。任何人都可以請幫忙。Web服務多次返回父標記

電流輸出

<emergencyEmails >[email protected]</emergencyEmails > 
<emergencyEmails >[email protected]</emergencyEmails > 
<emergencyEmails >[email protected]</emergencyEmails > 

我希望它是這樣

<emergencyEmails > 
<item>[email protected]</item> 
<item>[email protected]</item> 
<item>[email protected]</item> 
</emergencyEmails > 

電子郵件字段被定義爲一個字符串數組

package com.business.services; 

import javax.xml.bind.annotation.XmlElement; 
import javax.xml.bind.annotation.XmlType; 

@XmlType(propOrder={"companyId", "emergencyEmails", "language",  "normalEmails", "timezone"}) 
public class ProfileDetails 
{ 

private String companyId = null; 

private String[] emergencyEmails = null; 

private String language = null; 



public String getCompanyId() 
{ 
return this.companyId; 
} 

public void setCompanyId(String companyId) 
{ 
this.companyId = companyId; 
} 

public String[] getEmergencyEmails() 
{ 
return this.emergencyEmails; 
} 

public void setEmergencyEmails(String[] emergencyEmails) 
{ 
this.emergencyEmails = emergencyEmails; 
} 

public String getLanguage() 
{ 
return this.language; 
} 

public void setLanguage(String language) 
{ 
this.language = language; 
} 

} 

回答

0

你可以使用下面的註釋將數組「包裝」成一個元素:

@XmlElementWrapper(name="wrapper_tag_name") 
@XmlElement(name="element_tag_name") 

正如你所看到的,@XmlElementWrapper表示包裝元素名稱,而@XmlElement指定每個郵件的實際變量名。

現在,如果你註釋的電子郵件getter方法,像

@XmlElementWrapper(name="emergencyEmails") 
@XmlElement(name="item") 
public String[] getEmergencyEmails() { 
    return emergencyEmails; 
} 

你應該罰款。 註釋在這種情況下@XmlAccessorType(XmlAccessType.FIELD)該類領域本身,其他選項可能是一個解決方案

+0

Thannks很多.worked完美。 – user2134322