|
楼主 |
发表于 2017-9-19 17:27:31
|
显示全部楼层
本帖最后由 wuliang 于 2017-9-19 17:34 编辑
代码如下:
@SuppressWarnings("unchecked")
@RequestMapping(params = "importExcel", method = RequestMethod.POST)
@ResponseBody
public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
AjaxJson j = new AjaxJson();
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
MultipartFile file = entity.getValue();// 获取上传文件对象
ImportParams params = new ImportParams();
params.setTitleRows(2);
params.setHeadRows(1);
params.setNeedSave(true);
try {
List<ZyglRjTempEntity> listZyglRjTempEntitys = ExcelImportUtil.importExcel(file.getInputStream(),ZyglRjTempEntity.class,params);
//1.清空临时表
zyglRjTempService.clearData();
//写入临时表
zyglRjTempService.batchSave(listZyglRjTempEntitys);
j.setMsg("文件导入临时表成功!");
} catch (Exception e) {
j.setMsg("文件导入临时表失败!");
logger.error(ExceptionUtil.getExceptionMessage(e));
}finally{
try {
file.getInputStream().close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return j;
}
|
|