ExcelController.java 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package com.boman.file.controller;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.boman.common.core.web.domain.AjaxResult;
  4. import com.boman.domain.dto.ImportExcelDto;
  5. import com.boman.file.service.ISysFileService;
  6. import org.springframework.web.bind.annotation.PostMapping;
  7. import org.springframework.web.bind.annotation.RequestBody;
  8. import org.springframework.web.bind.annotation.RequestMapping;
  9. import org.springframework.web.bind.annotation.RestController;
  10. import org.springframework.web.multipart.MultipartFile;
  11. import javax.annotation.Resource;
  12. import java.util.List;
  13. /**
  14. * @author shiqian
  15. * @date 2021年06月07日 16:24
  16. **/
  17. @RestController
  18. @RequestMapping("/common/file")
  19. public class ExcelController {
  20. @Resource
  21. private ISysFileService fileService;
  22. /**
  23. * 功能描述:
  24. *
  25. * @param multipartFile multipartFile
  26. * @return void
  27. */
  28. // @PostMapping("/import")
  29. // public static AjaxResult importExcel(MultipartFile multipartFile) {
  30. // File file = FileUploadUtils.multipartFile2File(multipartFile);
  31. // EasyExcel.read(file, JSONObject.class, new ExcelListener<JSONObject>()).sheet().headRowNumber(1).doRead();
  32. // FileUploadUtils.delete(file);
  33. // return AjaxResult.success();
  34. // }
  35. /**
  36. * 功能描述: 通用的导入接口
  37. *
  38. * @param multipartFile MultipartFile
  39. * @param tableName tableName
  40. * @return void
  41. */
  42. @PostMapping("/import")
  43. public AjaxResult importExcelCommon(MultipartFile multipartFile, String tableName) throws Exception {
  44. List<JSONObject> result = null;
  45. try {
  46. result = fileService.importExcelCommon(multipartFile, tableName);
  47. } catch (Exception e) {
  48. e.printStackTrace();
  49. }
  50. return AjaxResult.success(result);
  51. }
  52. }