SpringBoot:spring boot檔案上傳【多檔案上傳】
阿新 • • 發佈:2019-01-16
原文轉自:http://www.vxzsk.com/638.html
檔案上傳主要分以下幾個步驟:
(1)新建maven java project;
(2)在pom.xml加入相應依賴;
(3)新建一個表單頁面(這裡使用thymleaf);
(4)編寫controller;
(5)測試;
(6)對上傳的檔案做一些限制;
(7)多檔案上傳實現
(1)新建maven java project
新建一個名稱為spring-boot-fileupload maven java專案;
2)在pom.xml加入相應依賴;
加入相應的maven依賴,具體看以下解釋:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
<!--
spring boot 父節點依賴,
引入這個之後相關的引入就不需要新增version配置,
spring boot會自動選擇最合適的版本進行新增。
-->
< parent >
< groupId >org.springframework.boot</ groupId >
< artifactId >spring-boot-starter-parent</ artifactId >
< version >1.3.3.RELEASE</ version >
</ parent >
< dependencies >
<!-- spring boot web支援:mvc,aop... -->
< dependency >
< groupId >org.springframework.boot</ groupId >
< artifactId >spring-boot-starter-web</ artifactId >
</ dependency >
<!-- thmleaf模板依賴. -->
< dependency >
< groupId >org.springframework.boot</ groupId >
< artifactId >spring-boot-starter-thymeleaf</ artifactId >
</ dependency >
</ dependencies >
< build >
< plugins >
<!-- 編譯版本; -->
< plugin >
< artifactId >maven-compiler-plugin</ artifactId >
< configuration >
< source >1.8</ source >
< target >1.8</ target >
</ configuration >
</ plugin >
</ plugins >
</ build >
|
(3)新建一個表單頁面(這裡使用thymleaf)
在src/main/resouces新建templates(如果看過博主之前的文章,應該知道,templates是spring boot存放模板檔案的路徑),在templates下新建一個file.html:
1
2
3
4
5
6
7
8
9
10
11
12
|