java - Web 服务哈希映射 Java 摆脱-
问题描述
我正在尝试将标签名称更改为团队,现在我的 Web 服务正在生成此响应:
<?xml version="1.0" encoding="UTF-8"?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<S:Body>
<ns2:MapTestResponse xmlns:ns2="http://infomracje/">
<return>
<Teams>
<item>
<Kryptonim>Ratownik 117</Kryptonim>
<Status>kon</Status>
</item>
<item>
<Kryptonim>Ratownik 19</Kryptonim>
<Status>got</Status>
</item>
<item>
<Kryptonim>Ratownik 154</Kryptonim>
<Status>kon</Status>
</item>
<item>
<Kryptonim>Ratownik 18</Kryptonim>
<Status>got</Status>
</item>
<item>
<Kryptonim>Ratownik 15</Kryptonim>
<Status>got</Status>
</item>
<item>
<Kryptonim>Ratownik 17</Kryptonim>
<Status>got</Status>
</item>
<item>
<Kryptonim>Ratownik 156</Kryptonim>
<Status>kon</Status>
</item>
<item>
<Kryptonim>Ratownik 16</Kryptonim>
<Status>got</Status>
</item>
<item>
<Kryptonim>Ratownik 111</Kryptonim>
<Status>got</Status>
</item>
<item>
<Kryptonim>Ratownik 22</Kryptonim>
<Status>kon</Status>
</item>
<item>
<Kryptonim>Ratownik 21</Kryptonim>
<Status>lot</Status>
</item>
<item>
<Kryptonim>Ratownik 24</Kryptonim>
<Status>lot</Status>
</item>
<item>
<Kryptonim>Ratownik 23</Kryptonim>
<Status>got</Status>
</item>
<item>
<Kryptonim>Ratownik 20</Kryptonim>
<Status>kon</Status>
</item>
<item>
<Kryptonim>EMS MXH</Kryptonim>
<Status>got</Status>
</item>
<item>
<Kryptonim>EMS MXI</Kryptonim>
<Status>kon</Status>
</item>
<item>
<Kryptonim>Ratownik 206</Kryptonim>
<Status>kon</Status>
</item>
<item>
<Kryptonim>Ratownik 106</Kryptonim>
<Status>kon</Status>
</item>
<item>
<Kryptonim>Ratownik 406</Kryptonim>
<Status>kon</Status>
</item>
<item>
<Kryptonim>Ratownik 306</Kryptonim>
<Status>kon</Status>
</item>
<item>
<Kryptonim>Ratownik 11</Kryptonim>
<Status>lot</Status>
</item>
<item>
<Kryptonim>Ratownik 10</Kryptonim>
<Status>got</Status>
</item>
<item>
<Kryptonim>Ratownik 13</Kryptonim>
<Status>got</Status>
</item>
<item>
<Kryptonim>Ratownik 12</Kryptonim>
<Status>got</Status>
</item>
<item>
<Kryptonim>Ratownik 1</Kryptonim>
<Status>lot</Status>
</item>
<item>
<Kryptonim>Ratownik 2</Kryptonim>
<Status>got</Status>
</item>
<item>
<Kryptonim>Ratownik 3</Kryptonim>
<Status>tra</Status>
</item>
<item>
<Kryptonim>Ratownik 4</Kryptonim>
<Status>got</Status>
</item>
<item>
<Kryptonim>Ratownik 5</Kryptonim>
<Status>got</Status>
</item>
<item>
<Kryptonim>Ratownik 6</Kryptonim>
<Status>got</Status>
</item>
<item>
<Kryptonim>Ratownik 7</Kryptonim>
<Status>got</Status>
</item>
<item>
<Kryptonim>Ratownik 8</Kryptonim>
<Status>got</Status>
</item>
<item>
<Kryptonim>Ratownik 9</Kryptonim>
<Status>got</Status>
</item>
</Teams>
</return>
</ns2:MapTestResponse>
</S:Body>
</S:Envelope>
这是我用来创建地图元素的代码:
public class MapElements {
@XmlElement public String Kryptonim;
@XmlElement public String Status;
private MapElements() {} //Required by JAXB
public MapElements(String Kryptonim, String Status)
{
this.Kryptonim = Kryptonim;
this.Status = Status;
}
}
这是一个 MapAdapter 类:
class MapAdapter extends XmlAdapter<MapElements[], Map<String, String>> {
public MapElements[] marshal(Map<String, String> arg0) throws Exception {
MapElements[] mapElements = new MapElements[arg0.size()];
int i = 0;
for (Map.Entry<String, String> entry : arg0.entrySet())
mapElements[i++] = new MapElements(entry.getKey(), entry.getValue());
return mapElements;
}
public Map<String, String> unmarshal(MapElements[] arg0) throws Exception {
Map<String, String> r = new HashMap<String, String>();
for (MapElements mapelement : arg0)
r.put(mapelement.Kryptonim, mapelement.Status);
return r;
}
}
最后是根类,我可以将信息从数据库放到
@XmlRootElement
public class Root
{
@XmlJavaTypeAdapter(MapAdapter.class)
private Map<String, String> Teams;
public Root()
{
Teams = new HashMap<String, String>();
}
public void TeamAdd(String kryptonim,String status) { Teams.put(kryptonim, status); }
}
所以我的问题是如何重命名这个<item>
标签?我对 Web 服务 Java 编程相当陌生。
解决方案
推荐阅读
- android - 扩展 FragmentStateAdapter 时每个构造函数有什么区别?
- php - 为什么它会显示以前选项卡中的项目?
- file - 尝试遍历文件时获取 java.nio.file.AccessDeniedException
- swift - 非可选的展开值
- excel - Excel 索引和匹配函数返回 #Ref 错误
- java - getActionCommand 与 .equal 不正确相等
- reactjs - 仅当用户在表单中输入可选字段时,才在 GET 请求中发送查询参数
- c - 按C中的特定元素对矩阵行进行排序的最佳方法
- offset - 偏移的奇怪行为
- python - QWebView 不显示等宽字体