ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## 一、概述 提供一个样板,用于标准化的处理文件导入数据的场景; ## 二、示范 前端把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文件,即可;