Springboot文件上傳功能簡(jiǎn)單測(cè)試
在static文件夾中創(chuàng)html頁面
內(nèi)容為:
<html> <head></head> <body> <form action="/fileuploadContorller" method="post" enctype="multipart/form-data"> <input type="file" name="file"/> <input type="submit" value="提交"> </form> </body> </html>
創(chuàng)建控制器
package com.mc_74120.springbootfileupload.controller; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import java.io.File; import java.io.IOException; @RestController public class FileUpLoadController { @PostMapping("/fileuploadContorller") public String fileUpLoadController(MultipartFile file) throws IOException { //MultipartFile對(duì)象的名稱必須和html中的文件上傳標(biāo)簽的名字相同 System.out.println(file.getOriginalFilename()); file.transferTo(new File("d:/"+file.getOriginalFilename())); return "ok"; } }
選擇文件
發(fā)送
找到該圖片
在application配置文件中 可以配置 文件的大小和request請(qǐng)求的大小
#配置單個(gè)文件的大小
spring.servlet.multipart.max-file-size=5MB
#配置一次請(qǐng)求總?cè)萘看笮?br /> spring.servlet.multipart.max-request-size=10MB
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Spring Boot應(yīng)用上傳文件時(shí)報(bào)錯(cuò)的原因及解決方案
這篇文章主要介紹了Spring Boot應(yīng)用上傳文件時(shí)報(bào)錯(cuò)的原因及解決方案,幫助大家更好的理解和學(xué)習(xí)使用spring boot框架,感興趣的朋友可以了解下2021-02-02SpringBoot集成阿里巴巴Druid監(jiān)控的示例代碼
這篇文章主要介紹了SpringBoot集成阿里巴巴Druid監(jiān)控的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-04-04Java圖片與二進(jìn)制相互轉(zhuǎn)換實(shí)現(xiàn)示例講解
這篇文章主要介紹了Java圖片與二進(jìn)制相互轉(zhuǎn)換實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧2023-03-03