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>

 

posted @ 2022-11-29 17:52  与f  阅读(79)  评论(0编辑  收藏  举报