🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## 一、概述 提供一个样板,用于标准化的处理文件导入数据的场景; ## 二、示范 前端把excel文件处理为base64,作为字符串post传入后端; controller: ``` @PostMapping("/api/business/card/cardinfo/import/candidate") public ResponseEntity<ResponseObject> changeLogo(@RequestHeader String rayAccessToken, @RequestParam String excelBase64) { return ResponseEntity.ok(cardInfoService.importCandidate(excelBase64)); } ``` service: ``` @RayServiceMethod @Transactional public ResponseObject importCandidate(String excelBase64) { Workbook wb = Base64Util.getWorkbookByBase64(Base64Util.trimHeadFromFront(excelBase64)); Sheet sheet = wb.getSheetAt(0); for (int i = 0; i < sheet.getPhysicalNumberOfRows(); i++) { Row row = sheet.getRow(i); CardInfoCandidate candidate = new CardInfoCandidate(); candidate.setAccessCode(ExcelUtil.getCellValue(row.getCell(0)).toString()); cardInfoCandidateDao.save(candidate); } return responseObj; } ``` >[danger] 导入非常简单,就是传入base64,后台解析成excel文件,即可;