MultipartFile保存文件

1、前端代码

<form id="unionpayEncSave" name="unionpayEncSave" method="post" action="${olt_url}/org/unionPay/encSave" enctype="multipart/form-data">
    <table class="form_table pt15 pb15" width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
            <td class="td_right">上传证书:</td>
            <td>
                <input type="hidden" name="unionpay_wechat_merchant_no" id="unionpay_wechat_merchant_no" />
                <input name="file_name" id="enc_name" class="easyui-filebox" style="height:30px" data-options="onChange:function(){$(this).val($(this).filebox('getValue'))},prompt:'敏感加密证书'" size="20" value="${enfiles.enc_name }">
                <input name="file_name" id="root_name" class="easyui-filebox" style="height:30px" data-options="onChange:function(){$(this).val($(this).filebox('getValue'))},prompt:'根证书'" size="20" value="${enfiles.root_name }">
                <input name="file_name" id="middle_name" class="easyui-filebox" style="height:30px" data-options="onChange:function(){$(this).val($(this).filebox('getValue'))},prompt:'中级证书'" size="20" value="${enfiles.middle_name }">
                <input name="file_name" id="sign_name" class="easyui-filebox" style="height:30px" data-options="onChange:function(){$(this).val($(this).filebox('getValue'))},prompt:'商户私钥证书'" size="20" value="${enfiles.sign_name }">
                <input type="submit" name="unionpayEncSaveBtn" id="unionpayEncSaveBtn" class="btn btn82 btn_save2" value="上传">
            </td>
            
        </tr>
    </table>
</form>

2、后端代码

String basePath = SKOrgService.class.getClassLoader().getResource("").getPath()+"key/unionpayqrcode/"+wechatMerchantNo;
for(MultipartFile file : files){
    String filePath = basePath + "/" + file.getOriginalFilename();
    File desFile = new File(filePath);
    if(!desFile.getParentFile().exists()){
        desFile.mkdirs();
    }
    try {
        file.transferTo(desFile);
    } catch (IllegalStateException | IOException e) {
        e.printStackTrace();
        result.put("msg", "处理失败");
        return result;
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Firechou

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值