Commit 7436c609 authored by suichenguang's avatar suichenguang

Merge branch 'dev' of…

Merge branch 'dev' of http://121.22.111.250:8000/YX_IDENT_auxiliary/YX_IDENT_beijing_auxiliary into dev
parents 49181791 9c472ca9
...@@ -22,7 +22,8 @@ import javax.servlet.http.HttpServletResponse; ...@@ -22,7 +22,8 @@ import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import java.io.*; import java.io.File;
import java.io.IOException;
import java.sql.Time; import java.sql.Time;
import java.util.*; import java.util.*;
...@@ -80,25 +81,25 @@ public class ReadExcelApi { ...@@ -80,25 +81,25 @@ public class ReadExcelApi {
// 如果fileitem中封装的是上传文件 // 如果fileitem中封装的是上传文件
// 得到上传的文件名称 // 得到上传的文件名称
filename = item.getName(); filename = item.getName();
File file = null;
try { try {
// 如果fileitem中封装的是普通输入项的数据 // 如果fileitem中封装的是普通输入项的数据
// 如果fileitem中封装的是上传文件 // 如果fileitem中封装的是上传文件
// 得到上传的文件名称 // 得到上传的文件名称
filename = item.getName(); filename = item.getName();
if (filename == null || filename.trim().equals("")) { System.out.println(item.getName()); // 为上传的key值
continue; System.out.println(item.getOriginalFilename()); // 上传的真实文件的文件名
File file = null;
try {
file = File.createTempFile("prefix", "_" + item.getOriginalFilename());
item.transferTo(file);
} catch (IOException e) {
e.printStackTrace();
} }
InputStream in = item.getInputStream();
OutputStream os = new FileOutputStream(file); // CommonsMultipartFile cf= (CommonsMultipartFile)item;
int bytesRead = 0; // DiskFileItem fi = (DiskFileItem)cf.getFileItem();
byte[] buffer = new byte[8192]; // File file = fi.getStoreLocation();
while ((bytesRead = in.read(buffer, 0, 8192)) != -1) {
os.write(buffer, 0, bytesRead);
}
os.close();
in.close();
ReadExcel readExcel = new ReadExcel(); ReadExcel readExcel = new ReadExcel();
List list1 = readExcel.readExcel(file); List list1 = readExcel.readExcel(file);
//保存EXCEL文件信息 //保存EXCEL文件信息
...@@ -138,20 +139,12 @@ public class ReadExcelApi { ...@@ -138,20 +139,12 @@ public class ReadExcelApi {
personPostEntity.setNatureOfTheInternal((String) list2.get(20)); personPostEntity.setNatureOfTheInternal((String) list2.get(20));
personPostEntity.setNatureOfTheInformation((String) list2.get(21)); personPostEntity.setNatureOfTheInformation((String) list2.get(21));
personPostEntity.setFirstWhite((String) list2.get(22)); personPostEntity.setFirstWhite((String) list2.get(22));
personPostEntity.setFileId(fileID); personPostEntity.setFileId(fileNameDicEntity.getFileId());
entityList.add(personPostEntity); entityList.add(personPostEntity);
} }
boolean b = personPostService.savePersonPost(entityList); boolean b = personPostService.savePersonPost(entityList);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
yxresp.outPutError("UnsupportedEncodingException", "上传文件时发现文件编码错误:" + e.getMessage());
continue;
} catch (IOException e) {
e.printStackTrace();
yxresp.outPutError("IOException", "上传文件时发生IO错误:" + e.getMessage());
continue;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
yxresp.outPutError("Exception", "上传文件时发生错误,非法XML文件:" + filename); yxresp.outPutError("Exception", "上传文件时发生错误,非法XML文件:" + filename);
......
...@@ -4,7 +4,9 @@ import jxl.Sheet; ...@@ -4,7 +4,9 @@ import jxl.Sheet;
import jxl.Workbook; import jxl.Workbook;
import jxl.read.biff.BiffException; import jxl.read.biff.BiffException;
import java.io.*; import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -14,12 +16,12 @@ import java.util.List; ...@@ -14,12 +16,12 @@ import java.util.List;
public class ReadExcel { public class ReadExcel {
// 去读Excel的方法readExcel,该方法的入口参数为一个File对象 // 去读Excel的方法readExcel,该方法的入口参数为一个File对象
public List readExcel(File file) { public List readExcel(File file) {
try { try {
// 创建输入流,读取Excel // // 创建输入流,读取Excel
InputStream is = new FileInputStream(file.getAbsolutePath()); // InputStream is = new FileInputStream(file.getAbsolutePath());
// jxl提供的Workbook类 // jxl提供的Workbook类
Workbook wb = Workbook.getWorkbook(is); Workbook wb = Workbook.getWorkbook(file);
// Excel的页签数量 // Excel的页签数量
int sheet_size = wb.getNumberOfSheets(); int sheet_size = wb.getNumberOfSheets();
for (int index = 0; index < sheet_size; index++) { for (int index = 0; index < sheet_size; index++) {
......
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