首页 > 其他分享 >spring mvc环境之上传文件设置(五)

spring mvc环境之上传文件设置(五)

时间:2022-11-29 18:01:07浏览次数:36  
标签:xml 文件 file spring mvc 设置 之上

spring mvc环境之上传文件设置

1.导入pom.xml依赖

2.spring-mvc.xml配置bean

3.测试

 

1.导入必要的依赖

    <!-- 上传组件包 -->
    <dependency>
      <groupId>commons-fileupload</groupId>
      <artifactId>commons-fileupload</artifactId>
      <version>1.3.3</version>
    </dependency>

2.在spring-mvc.xml文件配置上传的bean

  (还可以设置更多的参数...)

    <bean id="multipartResolver"
          class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <!-- 设置上传文件的最大尺寸为5MB -->
        <property name="maxUploadSize" value="5242880"/>
    </bean>

 

3.在控制器试试

    @RequestMapping("index06")
    public String index06(@RequestParam(name="file")MultipartFile file, Model model, HttpServletRequest request){

        System.out.println(file.toString());
        model.addAttribute("index02","index02");
        return "index01";
    }
<form action="./index/index06" method="post" enctype="multipart/form-data"  >
    <input type="file" name="file" />
    <input type="submit" value="submit" />
</form>

 

标签:xml,文件,file,spring,mvc,设置,之上
From: https://www.cnblogs.com/fps2tao/p/16936119.html

相关文章