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;@RestControllerpublic 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è)萘看笮pring.servlet.multipart.max-request-size=10MB
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 基于javaweb+jsp實(shí)現(xiàn)企業(yè)車輛管理系統(tǒng)2. XML在語音合成中的應(yīng)用3. php使用正則驗(yàn)證密碼字段的復(fù)雜強(qiáng)度原理詳細(xì)講解 原創(chuàng)4. 如何使用ASP.NET Core 配置文件5. asp.net core 認(rèn)證和授權(quán)實(shí)例詳解6. ASP.NET MVC使用Boostrap實(shí)現(xiàn)產(chǎn)品展示、查詢、排序、分頁7. jscript與vbscript 操作XML元素屬性的代碼8. ASP.NET Core 7 Razor Pages項(xiàng)目發(fā)布到IIS的詳細(xì)過程9. .NET中實(shí)現(xiàn)對(duì)象數(shù)據(jù)映射示例詳解10. uni-app結(jié)合.NET 7實(shí)現(xiàn)微信小程序訂閱消息推送
