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<T> list = ExcelImportUtil.importExcel(file.getInputStream(), clazz, params); //update-begin-author:taoyan date:20190528 for:批量插入数据 long start = System.currentTimeMillis(); service.saveBatch(list); //400条 saveBatch消耗时间1592毫秒 循环插入消耗时间1947毫秒 //1200条 saveBatch消耗时间3687毫秒 循环插入消耗时间5212毫秒 log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒"); //update-end-author:taoyan date:20190528 for:批量插入数据 return Result.ok("文件导入成功!数据行数:" + list.size()); } catch (Exception e) { //update-begin-author:taoyan date:20211124 for: 导入数据重复增加提示 String msg = e.getMessage(); log.error(msg, e); if(msg!=null && msg.indexOf("Duplicate entry")>=0){ return Result.error("文件导入失败:有重复数据!"); }else{ return Result.error("文件导入失败:" + e.getMessage()); } //update-end-author:taoyan date:20211124 for: 导入数据重复增加提示 } finally { try { file.getInputStream().close(); } catch (IOException e) { e.printStackTrace(); } } } return super.importExcel(request, response, RwaCaProviImport.class); }
java 上传下载基础数据信息
最新推荐文章于 2024-08-23 15:54:50 发布