【发布时间】:2020-04-06 19:20:47
【问题描述】:
你好我需要用spring boot打开excel文件并在数据库中添加数据, 但我收到此错误:构造函数 File(InputStream) 未定义
控制器:
@PostMapping("/upload")
public ResponseEntity<?> addRfp (@RequestParam("file") MultipartFile file) throws IOException, InvalidFormatException {
OPCPackage pkg = OPCPackage.open(new File(file.getInputStream()));
XSSFWorkbook wb = new XSSFWorkbook(pkg);
System.out.print(wb.getAllNames());
return null;
}
前端派对:
state = {
file : null
}
handlFile(e){
let file = e.target.files[0]
this.setState({file : file})
}
handleUpload(e){
let file = this.state.file;
let formdata = new FormData()
formdata.append('file', file)
formdata.append("name","ELMANDOUR AMINE")
axios({
url :'http://localhost:8080/rfp/upload',
method :'POST',
data : formdata
}).then((res)=>{})
}
形式:
input type="file" className="form-control" id="file" name="file" onChange={(e)=>this.handlFile(e)} required/>
</div>
</div>
<button id="button" type="button" onClick={(e)=>this.handleUpload(e)}> <img src={add} id="add" alt="Ajouter Region" /> </button>
请问我应该做什么,我需要打开文件 excel 并在我的数据库中添加数据,但是当我尝试打开文件时,我得到错误我应该做什么!
【问题讨论】:
标签: java reactjs spring-boot file-upload