@ApiOperation(value = "楼栋基本信息", notes = "需要登录。请求头携带Authorization字段")
@ApiImplicitParams({
@ApiImplicitParam(name = "excelFile", value = "excel文件", required = true, dataType = "int", paramType = "query")
})
@ApiResponses({
@ApiResponse(code = -1, message = "错误响应"),
@ApiResponse(code = 2000, message = "成功响应")
})
@PostMapping("/odsBulidingInfo")
public BaseResponse odsBulidingInfo(@RequestParam("excelFile") @ApiIgnore MultipartFile multipartfile) {
if(multipartfile==null){
return ("没有上传文件");
}
if(()){
return ("上传文件是空");
}
try{
InputStream inputStream = ();
String fileType = (inputStream);
if(!(, fileType)){
return ("只能上传xlsx类型文件");
}
(inputStream, , new InsertDB<OdsBulidingInfo>() {
@Override
public void save(List<OdsBulidingInfo> dataList){
for(OdsBulidingInfo item : dataList) {
item.setBuliding_info_id(());
int ii = (item);
}
}
});
}catch(Exception e){
throw new MyException((()));
}
return ();
}
上传Excel解析时报错:Convert excel format can try specifying the ‘excelType‘ yourself
原因是:因为在通过file获取的流类型,在读的时候,采用的同一个流,会导致excel类型出错。
解决方法:重新创建一个excel流,与获取文件流类型的流区别使用
InputStream inputStream = ();
String fileType = (());