手动调试
This commit is contained in:
parent
42336505d2
commit
1e405e2264
|
|
@ -27,6 +27,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
@ -346,6 +347,12 @@ public class TbPeopleServiceImpl implements TbPeopleService {
|
||||||
@Override
|
@Override
|
||||||
public AjaxResult importTbPeople(MultipartFile file) {
|
public AjaxResult importTbPeople(MultipartFile file) {
|
||||||
String fileName = file.getOriginalFilename();
|
String fileName = file.getOriginalFilename();
|
||||||
|
File tempFile = null;
|
||||||
|
try {
|
||||||
|
tempFile = File.createTempFile("upload_", ".tmp");
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
if (fileName != null) {
|
if (fileName != null) {
|
||||||
String fileExtension = fileName.substring(fileName.lastIndexOf(".") + 1);
|
String fileExtension = fileName.substring(fileName.lastIndexOf(".") + 1);
|
||||||
if (!Constants.XLSX.equalsIgnoreCase(fileExtension)) {
|
if (!Constants.XLSX.equalsIgnoreCase(fileExtension)) {
|
||||||
|
|
@ -353,9 +360,11 @@ public class TbPeopleServiceImpl implements TbPeopleService {
|
||||||
return AjaxResult.error("导入失败:文件后缀名不符合要求,必须为xlsx结尾");
|
return AjaxResult.error("导入失败:文件后缀名不符合要求,必须为xlsx结尾");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
InputStream inputStream = null;
|
||||||
|
Workbook workbook = null;
|
||||||
try {
|
try {
|
||||||
InputStream inputStream = file.getInputStream();
|
inputStream = file.getInputStream();
|
||||||
Workbook workbook = new XSSFWorkbook(inputStream);
|
workbook = new XSSFWorkbook(inputStream);
|
||||||
Sheet sheet = workbook.getSheetAt(0);
|
Sheet sheet = workbook.getSheetAt(0);
|
||||||
// 得到Excel的行数
|
// 得到Excel的行数
|
||||||
int totalRows = sheet.getPhysicalNumberOfRows();
|
int totalRows = sheet.getPhysicalNumberOfRows();
|
||||||
|
|
@ -418,6 +427,27 @@ public class TbPeopleServiceImpl implements TbPeopleService {
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (workbook != null) {
|
||||||
|
try {
|
||||||
|
// 关闭工作簿
|
||||||
|
workbook.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (inputStream != null) {
|
||||||
|
try {
|
||||||
|
// 关闭输入流
|
||||||
|
inputStream.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 删除临时文件
|
||||||
|
if (tempFile != null && tempFile.exists()) {
|
||||||
|
tempFile.delete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return AjaxResult.error(ExceptionEnum.SAVE_TO_DATABASE.getCode(), ExceptionEnum.SAVE_TO_DATABASE.getMsg());
|
return AjaxResult.error(ExceptionEnum.SAVE_TO_DATABASE.getCode(), ExceptionEnum.SAVE_TO_DATABASE.getMsg());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue