需求:代码需实现,上传excel到服务器,执行批量导入操作
操作方法:
- 将已编写好的excel,复制当前分支resource目录下,如:D:\work\Git-Code\autotest\src\main\resources(或者new一个文件)
- IDEA,resource文件夹下找到复制文件,右键-》git-》add
- 当excel文件更新时,右键文件-》syonchronize 'excel文件名',可刷新
- 执行代码查找文件,MajorCustomOrder为当前类名
CustomOrder.class.getClassLoader().getResource("cus.xlsx").getFile();
- 实现
/* * 上传批量下单excel * */ private String upFilePost() throws UnsupportedEncodingException{ String file; String url =host; String jUrl = Client.joinParams(url,watsonParmas); file = CustomOrder.class.getClassLoader().getResource("cus.xlsx").getFile(); RequestBody fileBody = RequestBody.create(MediaType.parse("application/octet-stream"),new File(file));