|
|
|
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;
|
|
|
|
private String bsnTrpDays;
|
|
|
|
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{" +
|
|
|
|
"startDate='" + startDate + '\'' +
|
|
|
|
", endDate='" + endDate + '\'' +
|
|
|
|
", bsnTrpDays='" + bsnTrpDays + '\'' +
|
|
|
|
", jrnyPath='" + jrnyPath + '\'' +
|
|
|
|
", jrnyExpln='" + jrnyExpln + '\'' +
|
|
|
|
'}';
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getStartDate() {
|
|
|
|
return startDate;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setStartDate(String startDate) {
|
|
|
|
this.startDate = startDate;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getEndDate() {
|
|
|
|
return endDate;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setEndDate(String endDate) {
|
|
|
|
this.endDate = endDate;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getBsnTrpDays() {
|
|
|
|
return bsnTrpDays;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setBsnTrpDays(String bsnTrpDays) {
|
|
|
|
this.bsnTrpDays = bsnTrpDays;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getJrnyPath() {
|
|
|
|
return jrnyPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setJrnyPath(String jrnyPath) {
|
|
|
|
this.jrnyPath = jrnyPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getJrnyExpln() {
|
|
|
|
return jrnyExpln;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|