码迷,mamicode.com
首页 > Web开发 > 详细

上传文件(Uploading Files)

时间:2018-02-22 19:49:23      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:get   使用   自动   boot   pos   config   init   uil   ini   

创建可以接收HTTP多部分文件上传的服务器应用程序

你会建立什么

您将创建一个接受文件上传的Spring Boot Web应用程序。您还将构建一个简单的HTML界面来上传测试文件。

环境依赖

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        </dependency>

创建一个应用程序类

要开始一个Spring Boot MVC应用程序,我们首先需要一个启动器; 这里,spring-boot-starter-thymeleafspring-boot-starter-web已经被添加为依赖。要使用Servlet容器上传文件,您需要注册一个MultipartConfigElement类(它是web.xml中的<multipart-config>)。感谢Spring Boot,一切都为您自动配置!

作为自动配置Spring MVC的一部分,Spring Boot将创建一个MultipartConfigElement bean并为文件上传做好准备。

创建一个文件上传控制器

初始应用程序已经包含几个类来处理在磁盘上存储和加载上传的文件; 

 

参考资料:Uploading Files

上传文件(Uploading Files)

标签:get   使用   自动   boot   pos   config   init   uil   ini   

原文地址:https://www.cnblogs.com/xsj891107/p/8459642.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!