/**
* 组织生成xml的数据
*
* @param data
* @param <T>
* @return
*/
public static <T> String organizeXMLData(List<T> data) {
StringBuilder xmlBuilder = new StringBuilder();
xmlBuilder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
xmlBuilder.append("<n>");
for (T t : data) {
StringBuilder content = new StringBuilder();
Map<String, Object> map = ObjectMapperUtil.toJavaObject(ObjectMapperUtil.toJSONString(t), Map.class);
map.entrySet().forEach(m -> {
content.append(m.getKey() + "=" + "\"" + m.getValue() + "\"" + " ");
});
xmlBuilder.append("<r " + content + "/>");
}
xmlBuilder.append("</n>\r\n");
return xmlBuilder.toString();
}
组织生成XML格式文件内容
于 2023-12-29 13:27:20 首次发布