前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >EasyUI+SpringMVC 单个/多个文件上传

EasyUI+SpringMVC 单个/多个文件上传

作者头像
用户5640963
发布2019-07-28 11:39:29
1.5K0
发布2019-07-28 11:39:29
举报
文章被收录于专栏:卯金刀GG

1、js文件

function uplodad( $('#fromNameId').form({ url:'controllerurl', onSubmit: function(){ //uploda before something }, success:function(data){ //upload after something },error:function(date){ $.messager.alert(data.errormsg); } }); $('#fromNameId').submit(); );

2、jsp文件

<form id="rundApplyFrom" method="post" enctype="multipart/form-data"> <tr id="trIdCard"> <td>msg:</td> <td><input class="easyui-filebox" id="uploadId" name="sourceFile" style="width:200px"></td> </tr> </from>

3、spring.xml配置文件

<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="defaultEncoding" value="UTF-8"/> </bean>

4、pojo文件

public class AReFundApplyProcess implements Serializable {

代码语言:javascript
复制
   private String prosn  ; 
   private String applyid; 
   private byte[] annex  ; 
   private Object content;
   private MultipartFile[] sourceFile;

// sourceFile geter, seter }

5、javaservice文件

/** * uplodaApplyFile * 方法描述:文件上传方法; * @param request */ public void uplodaApplyFile( AReFundApplyProcess arProcess, AReFundApply aRefundApply){

代码语言:javascript
复制
    MultipartFile[] uploadfile=arProcess.getSourceFile();//这里用于获取前台传入Bean中Byte字段中的流;
    InputStream fileIs= null;                            //因为案例中是多文件上传,所以是数组;
    aRefundApply.setOrderno(arProcess.getProsn());
    
    try {
        if(uploadfile != null&& uploadfile.length>0){
            for (int i = 0; i < uploadfile.length; i++) {
                MultipartFile file=uploadfile[i];
                fileIs= file.getInputStream();
                byte[] b = FileCopyUtils.copyToByteArray(fileIs);
                if(b.length>0){
                    arProcess.setAnnex(b);
                    aReFundApplyCheckService.insertAReFundApplyProcess(arProcess);
                }
            }
        }
    } catch (IOException e) {
        log.error("上传文件异常...",e);
    }
}

参考,待验证。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档