|
|
|
@ -1,5 +1,15 @@
|
|
|
|
|
package com.engine.custom.sl.entity;
|
|
|
|
|
|
|
|
|
|
import com.engine.custom.hg.service.TextDocFileService;
|
|
|
|
|
|
|
|
|
|
import javax.xml.bind.JAXBContext;
|
|
|
|
|
import javax.xml.bind.JAXBException;
|
|
|
|
|
import javax.xml.bind.Marshaller;
|
|
|
|
|
import java.io.StringWriter;
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
public class JourneyInfo {
|
|
|
|
|
private String startDate;
|
|
|
|
|
private String endDate;
|
|
|
|
@ -7,6 +17,17 @@ public class JourneyInfo {
|
|
|
|
|
private String jrnyPath;
|
|
|
|
|
private String jrnyExpln;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String toXMLString() {
|
|
|
|
|
return "<expndArray>" +
|
|
|
|
|
"<startDate>" + startDate + "</startDate>"+
|
|
|
|
|
"<endDate>" + endDate +
|
|
|
|
|
"<bsnTrpDays>" + bsnTrpDays +
|
|
|
|
|
"<jrnyPath>" + jrnyPath +
|
|
|
|
|
"<jrnyExpln>" + jrnyExpln +
|
|
|
|
|
"</expndArray>" ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String toString() {
|
|
|
|
|
return "JourneyInfo{" +
|
|
|
|
@ -57,4 +78,49 @@ public class JourneyInfo {
|
|
|
|
|
public void setJrnyExpln(String jrnyExpln) {
|
|
|
|
|
this.jrnyExpln = jrnyExpln;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static String convertObjectToXml(Object object) {
|
|
|
|
|
StringBuilder xmlBuilder = new StringBuilder("<" + object.getClass().getSimpleName() + ">");
|
|
|
|
|
Field[] fields = object.getClass().getDeclaredFields();
|
|
|
|
|
Map<String, Object> attributes = new LinkedHashMap<>();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
for (Field field : fields) {
|
|
|
|
|
field.setAccessible(true);
|
|
|
|
|
Object value = field.get(object);
|
|
|
|
|
if (value != null) {
|
|
|
|
|
String fieldName = field.getName();
|
|
|
|
|
xmlBuilder.append("<").append(fieldName).append(">")
|
|
|
|
|
.append(value)
|
|
|
|
|
.append("</").append(fieldName).append(">");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (IllegalAccessException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
xmlBuilder.append("</" + object.getClass().getSimpleName() + ">");
|
|
|
|
|
return xmlBuilder.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
TravelToEsbBean textDocFileService = new TravelToEsbBean();
|
|
|
|
|
textDocFileService.setAcsryNums("1");
|
|
|
|
|
textDocFileService.setExpnsAmt("2");
|
|
|
|
|
textDocFileService.setExpnsRsn("3");
|
|
|
|
|
textDocFileService.setRemark("5");
|
|
|
|
|
textDocFileService.setOperatorName("fjkgnvbhui");
|
|
|
|
|
|
|
|
|
|
// 调用工具类将对象转换为 XML 字符串
|
|
|
|
|
String xmlString = null;
|
|
|
|
|
|
|
|
|
|
xmlString = convertObjectToXml(textDocFileService);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 打印生成的 XML 字符串
|
|
|
|
|
System.out.println(xmlString);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|