Springboot文件上傳功能簡(jiǎn)單測(cè)試
在static文件夾中創(chuàng)html頁(yè)面
內(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ì)象的名稱(chēng)必須和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)文章
SpringBoot中EasyExcel實(shí)現(xiàn)Excel文件的導(dǎo)入導(dǎo)出
這篇文章主要介紹了SpringBoot中EasyExcel實(shí)現(xiàn)Excel文件的導(dǎo)入導(dǎo)出,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-10-10
Mybatis基于TypeHandler實(shí)現(xiàn)敏感數(shù)據(jù)加密
業(yè)務(wù)場(chǎng)景中經(jīng)常會(huì)遇到諸如用戶(hù)手機(jī)號(hào),身份證號(hào),銀行卡號(hào),郵箱,地址,密碼等等信息,屬于敏感信息,本文就來(lái)介紹一下Mybatis基于TypeHandler實(shí)現(xiàn)敏感數(shù)據(jù)加密,感興趣的可以了解一下2023-10-10
Spring配置和使用Properties文件的詳細(xì)步驟
在Spring框架中,.properties 文件通常用于存儲(chǔ)配置信息,如數(shù)據(jù)庫(kù)連接、服務(wù)地址、應(yīng)用參數(shù)等,本文給大家介紹了Spring配置和使用Properties文件的詳細(xì)步驟,需要的朋友可以參考下2024-05-05
JPA如何使用entityManager執(zhí)行SQL并指定返回類(lèi)型
這篇文章主要介紹了JPA使用entityManager執(zhí)行SQL并指定返回類(lèi)型的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-06-06
java利用socket通信實(shí)現(xiàn)Modbus-RTU通信協(xié)議的示例代碼
這篇文章主要介紹了java利用socket通信實(shí)現(xiàn)Modbus-RTU通信協(xié)議的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-04-04

