我需要使用rest模板发送请求。在发送之前,我需要在发送请求时将对象编组为xml。我得到了请求的响应,但是以XML格式。然后我需要将响应xml转换为Object,以便将结果显示在接口上。
以下是我发送请求的控制器
@RequestMapping("/searchSummon")
public String Search(Model model)
{
model.addAttribute("jaxbExample", new JAXBExample());
model.addAttribute("pdxiRes", new PDXIRes());
JAXBExample jaxbExample = new JAXBExample();
String create_xml = jaxbExample.CreateXML();
System.out.println(create_xml);
RestTemplate restTemplate = new RestTemplate();
String a = restTemplate.postForObject("http://192.168.80.30/summon-
V2/example", "<?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE PDXIReq
SYSTEM 'summon.dtd'>" + create_xml,String.class);
System.out.println(a);
return "searchSummon";
}
我怎样才能解开&#39; a&#39;反对? 响应类 的 PDXIRes 头 请求 细节 状态
xml for response(&#39; a&#39;)
<?xml version="1.0" encoding="utf-8"?>
<PDXIRes>
<header>
<sp_code>abc017637m</sp_code>
</header>
<request id="1sq1216272728732">
<id_no>683642435</id_no>
<name>SALLY</name>
<max_index>1024</max_index>
<total_summons>2</total_summons>
<summons_detail>
<row num="1">
<summons_id>1810000200002AQ639332</summons_id>
<vehicle>NN162</vehicle>
</row>
<row num="2">
<summons_id>1810000200002AM947772</summons_id>
<vehicle>NN162</vehicle
</row>
</summons_detail>
<status>
<status_code>01</status_code>
<status_msg>Successful</status_msg>
</status>
</request>
</PDXIRes>
答案 0 :(得分:0)
你可以使用Unmarshaller来做到这一点。
echo $_product->getShortDescription().' Buy ('.$_product->getName().') at affordable price, Pay cash on delivery in UAE.';