本文主要是介绍导入--多页签,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1.前端上传excel文件
2.后台接收并转行为map对象
Map<Integer, Class> map = new HashMap<Integer, Class>();
map.put(0, HandbookExportExg.class);
map.put(1, HandbookExportImg.class);
map.put(2, HandbookExportBom.class);
Map<Integer, List> returnMap = FileUtils.importExcelByMap(multipartFile, 0, 1, map);
2.解析文件并封装到Map对象中
public static Map<Integer, List> importExcelByMap(MultipartFile file, Integer titleRows, Integer headerRows, Map<Integer, Class> map) {if (file == null || map == null) {return null;}Map<Integer, List> returnMap = new HashMap<Integer, List>();Set<Integer> keySet = map.keySet();for (Integer sheetNum : keySet) {Class pojoClass = map.get(sheetNum);ImportParams params = new ImportParams();params.setTitleRows(titleRows);params.setHeadRows(headerRows);params.setStartSheetIndex(sheetNum);params.setSheetNum(1);List<T> list = null;try {list = ExcelImportUtil.importExcel(file.getInputStream(), pojoClass, params);returnMap.put(sheetNum, list);} catch (NoSuchElementException e) {// throw new NormalException("excel文件不能为空");e.printStackTrace();} catch (Exception e) {//throw new NormalException(e.getMessage());e.printStackTrace();}}return returnMap;
}
3.后台进行验证并保存到数据库中
//获得需要导入的数据 List<HandbookExportExg> parseExgList = map.get(0); List<HandbookExportImg> parseImgList = map.get(1); List<HandbookExportBom> parseBomList = map.get(2);
//批量插入 bomInputDAOService.batchSaveBomInput(waitSaveBomList); imgInputDAOService.saveImgInput(waitSaveImgList); exgInputDAOService.batchSaveExgInput(waitSaveExgList);
这篇关于导入--多页签的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!