2 回答

TA貢獻1757條經驗 獲得超7個贊
經過 1 天的搜索,我發現 Response 應該以字符串形式返回,并且在 Document 類的幫助下,我們可以從字符串中解析新的 xml,然后我們可以做我們應該做的事情。Request1 是其他請求中的第一個 xml 數據,它來自 Other1 xml數據沒關系。
@RequestMapping(name = "/a",method = RequestMethod.POST,produces = MediaType.ALL_VALUE)
private ResponseEntity<String> getIt(@RequestBody String path) throws ParserConfigurationException, IOException, SAXException {
Document doc = DocumentBuilderFactory.newInstance()
.newDocumentBuilder()
.parse(new InputSource(new StringReader(path)));
if(path.contains("Request1")){
NodeList tagName = doc.getElementsByTagName("id");
if(tagName.getLength() > 0){
System.out.println(tagName.item(0).getTextContent());
}
}
if(path.contains("Other1")){
NodeList tagName = doc.getElementsByTagName("fio");
if(tagName.getLength() > 0){
System.out.println(tagName.item(0).getTextContent());
}
}
return ResponseEntity.ok("SAVED");
}
添加回答
舉報