String errCode = ErrorCodeEnum.RECEIPT_ORDER_GET.getCode(); String errDesc = ErrorCodeEnum.RECEIPT_ORDER_GET.getDesc(); BillHead billHead = new BillHead(); billHead.setCopListNo("12312524"); billHead.setCopNo("18"); Object response = new Object(); XmlMapper xmlMapper = new XmlMapper(); xmlMapper.enable(SerializationFeature.INDENT_OUTPUT); String xml = xmlMapper.writeValueAsString(billHead); String axml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+xml; String responsea=null; return axml; 返回值为: <?xml version="1.0" encoding="UTF-8"?> <BillHead> <copListNo>12312524</copListNo> <copNo>18</copNo> <CopListNo>12312524</CopListNo> <CopNo>18</CopNo> 修改以上代码使其返回值为<?xml version="1.0" encoding="UTF-8"?> <BillHead> <CopListNo>12312524</CopListNo> <CopNo>18</CopNo>
时间: 2023-11-28 17:49:43 浏览: 61
修改BillHead类中的属性名,将其中的首字母小写改为大写,即可解决问题。
修改后的代码如下:
```
String errCode = ErrorCodeEnum.RECEIPT_ORDER_GET.getCode();
String errDesc = ErrorCodeEnum.RECEIPT_ORDER_GET.getDesc();
BillHead billHead = new BillHead();
billHead.setCopListNo("12312524");
billHead.setCopNo("18");
Object response = new Object();
XmlMapper xmlMapper = new XmlMapper();
xmlMapper.enable(SerializationFeature.INDENT_OUTPUT);
String xml = xmlMapper.writeValueAsString(billHead);
String axml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+xml;
String responsea=null;
return axml;
```
返回值为:
```
<?xml version="1.0" encoding="UTF-8"?>
<BillHead>
<CopListNo>12312524</CopListNo>
<CopNo>18</CopNo>
</BillHead>
```
阅读全文