maven项目添加自定义文件

本文介绍如何在Maven项目中添加自定义的xlsx文件,详细步骤包括将文件放入resource目录,使用IDEA进行Git操作同步文件,以及在代码中查找文件。关键在于maven的pom.xml配置,需要正确设置resources标签,确保xlsx文件在编译时被包含,以避免运行时找不到文件的问题。
摘要由CSDN通过智能技术生成

需求:代码需实现,上传excel到服务器,执行批量导入操作

操作方法:

  1. 将已编写好的excel,复制当前分支resource目录下,如:D:\work\Git-Code\autotest\src\main\resources(或者new一个文件)
  2. IDEA,resource文件夹下找到复制文件,右键-》git-》add
  3. 当excel文件更新时,右键文件-》syonchronize 'excel文件名',可刷新
  4. 执行代码查找文件,MajorCustomOrder为当前类名
    CustomOrder.class.getClassLoader().getResource("cus.xlsx").getFile();

     

  5. 实现
     
        /*
        * 上传批量下单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));
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值