其他分享
首页 > 其他分享> > 问答中编辑富文本框中的图片上传不了

问答中编辑富文本框中的图片上传不了

作者:互联网

1.spring-servlet.xml添加下面的代码

<bean id="multipartResolver"
          class="com.velcro.base.file.CustomCommonsMultipartResolver"> <!-- 设置上传文件的最大尺寸为500MB (10MB=10485760)-->
        <property name="excludeUrls">
            <list>
                <value>/kms/team/thoto/add</value>
                <value>/bbs/fileUpload</value>
                <value>/kms/excel/importExcel</value>
            </list>
        </property>
        <property name="maxUploadSize">
            <value>524288000</value>
        </property> <!--设置编码,与jsp页面编码一致-->
        <property name="defaultEncoding">
            <value>UTF-8</value>
        </property>
    </bean>

2.添加CustomCommonsMultipartResolver类

package com.velcro.base.file;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.multipart.commons.CommonsMultipartResolver;

import java.util.List;

/**
 * 不转换request中的文件流
 * Controller里的request对象是初始时HttpServletRequest的对象。刚开始认为fileList对象不会为空,但是却空。主要原因在于我配置的spring MVC的文件解析器如下:
 <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
 <property name="maxUploadSize" value="10485760" />
 </bean>
 关键之处在于CommonsMultipartResolver中的方法parseRequest已经解析过request对象了.
 自定义一个类
 * @author ZamXie
 *
 */
public class CustomCommonsMultipartResolver extends CommonsMultipartResolver {

    private List<String> excludeUrls;

    public void setExcludeUrls(List<String> excludeUrls) {
        this.excludeUrls = excludeUrls;
    }

    public List<String> getExcludeUrls() {
        return excludeUrls;
    }

    @Override
    public boolean isMultipart(HttpServletRequest request) {
        String requestURL=request.getRequestURI();
        if(requestURL.contains(".do")){
            requestURL=requestURL.substring(0,requestURL.indexOf(".do"));
            if(excludeUrls.contains(requestURL)){
                return false;
            }else{
                return super.isMultipart(request);
            }
        }
        return false;
    }

}

参考系统:cyy

标签:List,return,上传,excludeUrls,requestURL,request,文本框,问答,public
来源: https://www.cnblogs.com/jk200/p/16140710.html