void uploadDeviceType(@RequestParam("uploadFile") MultipartFile multipartFile) {
//进行文件读取配置
CsvReadConfig csvReadConfig = new CsvReadConfig();
csvReadConfig.setSkipEmptyRows(true);
csvReadConfig.setContainsHeader(true);
//构建 CsvReader 对象
CsvReader csvReader = CsvUtil.getReader(csvReadConfig);
//读取文件,封装成 Bean
if (null == multipartFile) {
log.info("设备类型文件不能为空!");
return new BaseResponse<>(ApiResponseStatus.COMMON_FAIL);
}
ArrayList<DeviceType> deviceTypeList = new ArrayList<DeviceType>();
try {
File file = uploadFile(multipartFile);
deviceTypeList = (ArrayList<DeviceType>) csvReader.read(new FileReader(file), DeviceType.class);
file.delete();
} catch (Exception e) {
log.info("设备类型文件上传失败!!!");
}
//判重后,添加设备类型入库
for(DeviceType deviceType:deviceTypeList){
}
}
postman文件上传:
网友评论