Commit 9651b5f6 authored by suichenguang's avatar suichenguang

解析XML包

parent 6ad6ff58
...@@ -6,24 +6,20 @@ import com.yxproject.start.service.ImportXmlService; ...@@ -6,24 +6,20 @@ import com.yxproject.start.service.ImportXmlService;
import com.yxproject.start.utils.IDCardFactory; import com.yxproject.start.utils.IDCardFactory;
import com.yxproject.start.utils.YXJSONResponse; import com.yxproject.start.utils.YXJSONResponse;
import com.yxproject.start.utils.YXStringUtils; import com.yxproject.start.utils.YXStringUtils;
import org.apache.catalina.Manager;
import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException; import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.dom4j.DocumentException; import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
......
package com.yxproject.start.api;
import com.yxproject.start.entity.PreproPersonEntity;
import com.yxproject.start.service.ImportXmlService;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* Created by Administrator on 2019/2/15.
*/
@RestController
@RequestMapping("yingxin")
public class YingxinApi {
@Autowired
private ImportXmlService importXmlService;
/*导入XML文件*/
@RequestMapping("importXmlData")
public List<PreproPersonEntity> importXmlData(){
List<PreproPersonEntity> list=new ArrayList<>();
try{
File file = new File("D:\\dengzhou.xml");
// 该文件目录下文件全部放入数组
File[] files = file.listFiles();
if(files!=null){
for(int i=0;i<files.length;i++){
String fileName=files[i].getName();
if(fileName.endsWith("xml")){
SAXReader reader = new SAXReader();
//读取文件到document中
Document doc=reader.read(file);
//获取xml文件的根节点
Element rootElement=doc.getRootElement();
Element data = rootElement.element("DATA");
//定义一个Element用于遍历
Element fooElement;
//遍历所有名叫“RECORD”的节点
for (Iterator j = data.elementIterator("RECORD"); j.hasNext();) {
fooElement = (Element) j.next();
PreproPersonEntity preproPersonEntity = new PreproPersonEntity();
preproPersonEntity.setJmsfzslh(fooElement.elementText("jmsfzslh"));
preproPersonEntity.setGmsfhm(fooElement.elementText("gmsfhm"));
preproPersonEntity.setXm(fooElement.elementText("xm"));
preproPersonEntity.setXbdm(fooElement.elementText("xbdm"));
preproPersonEntity.setMzdm(fooElement.elementText("mzdm"));
preproPersonEntity.setCsrq(fooElement.elementText("csrq"));
preproPersonEntity.setSsxqdm(fooElement.elementText("ssxqdm"));
preproPersonEntity.setDzmc(fooElement.elementText("dzmc"));
preproPersonEntity.setSdxp(fooElement.elementText("sdxp"));
preproPersonEntity.setZwyZwtxsj(fooElement.elementText("zwyZwtxsj"));
preproPersonEntity.setZwyZwtzsj(fooElement.elementText("zwyZwtzsj"));
preproPersonEntity.setZweZwtxsj(fooElement.elementText("zweZwtxsj"));
preproPersonEntity.setZweZwtzsj(fooElement.elementText("zweZwtzsj"));
preproPersonEntity.setQfjgGajgmc(fooElement.elementText("qfjgGajgmc"));
preproPersonEntity.setYxqqsrq(fooElement.elementText("yxqqsrq"));
preproPersonEntity.setYxqjzrq(fooElement.elementText("yxqjzrq"));
preproPersonEntity.setJmsfzslyydm(fooElement.elementText("jmsfzslyydm"));
preproPersonEntity.setJmsfzzzlxdm(fooElement.elementText("jmsfzzzlxdm"));
preproPersonEntity.setJmsfzlzfsdm(fooElement.elementText("jmsfzlzfsdm"));
preproPersonEntity.setSjrXm(fooElement.elementText("sjrXm"));
preproPersonEntity.setSjrLxdh(fooElement.elementText("sjrLxdh"));
preproPersonEntity.setSjrYzbm(fooElement.elementText("sjrYzbm"));
preproPersonEntity.setSjrTxdz(fooElement.elementText("sjrTxdz"));
preproPersonEntity.setSid(fooElement.elementText("sid"));
list.add(preproPersonEntity);
}
ImportXmlService.importPersonXml(list);
}else {
continue;
}
}
}
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return list;
}
}
package com.yxproject.start.mapper;
public interface Analysis {
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment