SpringBoot: 6.文件上传(转)
1、编写页面uploadFile.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>上传文件</title>
</head>
<body>
<form action="uploadFile" method="post" enctype="multipart/form-data">
<input type="file" name="myfile">
<input type="submit" value="上传">
</form>
</body>
</html>

2、编写controller

package com.bjsxt.controller; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile; import java.io.File;
import java.util.HashMap;
import java.util.Map; /**
* Created by Administrator on 2019/2/5.
*/
@RestController
public class UploadFileController { @RequestMapping(value = "/uploadFile",method = RequestMethod.POST)
public Map<String,Object> uploadFile(MultipartFile myfile){
Map<String,Object> returnMap=new HashMap<String,Object>();
try{
myfile.transferTo(new File("e:/"+myfile.getOriginalFilename()));
returnMap.put("msg","上传成功");
}catch (Exception e){
e.printStackTrace();
returnMap.put("msg","上传失败");
}
return returnMap;
} }

3、编写启动类

package com.bjsxt; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; /**
* Created by Administrator on 2019/2/5.
*/
@SpringBootApplication
public class App { public static void main(String[] args){
SpringApplication.run(App.class,args);
}
}

4、设置上传文件的大小限制
需要添加一个springboot的配置文件,名字为application.properties,放在resource文件夹下,添加以下内容
#设置单个文件上传的最大大小
spring.http.multipart.maxFileSize=200MB
#设置一次请求上传文件的总容量的大小
spring.http.multipart.maxRequestSize=200MB
5、启动项目即可,在浏览器中访问http://localhost:8080/uploadFile.html即可
目录结构
SpringBoot: 6.文件上传(转)的更多相关文章
- SpringBoot图文教程4—SpringBoot 实现文件上传下载
有天上飞的概念,就要有落地的实现 概念+代码实现是本文的特点,教程将涵盖完整的图文教程,代码案例 文章结尾配套自测面试题,学完技术自我测试更扎实 概念十遍不如代码一遍,朋友,希望你把文中所有的代码案例 ...
- SpringBoot 整合文件上传 elment Ui 上传组件
SpringBoot 整合文件上传 elment Ui 上传组件 本文章记录 自己学习使用 侵权必删! 前端代码 博主最近在学 elment Ui 所以 前端使用 elmentUi 的 upload ...
- springboot+web文件上传和下载
一.首先安装mysql数据库,开启web服务器. 二.pom.xml文件依赖包配置如下: <?xml version="1.0" encoding="UTF-8&q ...
- SpringBoot(3) 文件上传和访问
springboot文件上传 MultipartFile file,源自SpringMVC MultipartFile 对象的transferTo方法,用于文件保存(效率和操作比原先用FileOutS ...
- SpringBoot的文件上传
先在src/main/resources下新建一个static目录用以存放html页面,简单的html页面如下 <!DOCTYPE html> <html> <head& ...
- springBoot的文件上传功能
知识点: 后台:将上传的图片写入指定服务器路径,保存起来,返回上传后的图片路径(在springBoot中,参考博客:http://blog.csdn.net/change_on/article/det ...
- SpringBoot下文件上传与下载的实现
原文:http://blog.csdn.net/colton_null/article/details/76696674 SpringBoot后台如何实现文件上传下载? 最近做的一个项目涉及到文件上传 ...
- Angular14 利用Angular2实现文件上传的前端、利用springBoot实现文件上传的后台、跨域问题
一.angular2实现文件上传前端 Angular2使用ng2-file-upload上传文件,Angular2中有两个比较好用的上传文件的第三方库,一个是ng2-file-upload,一个是ng ...
- springboot 修改文件上传大小限制
springboot 1.5.9文件上传大小限制spring:http:multipart:maxFileSize:50MbmaxRequestSize:50Mb springboot 2.0文件上传 ...
- SpringBoot实现文件上传
前言参考:快速开发第一个SpringBoot应用 这篇文章会讲解如何使用SpringBoot完成一个文件上传的过程,并且附带一些SpringBoot开发中需要注意的地方 首先我们写一个文件上传的htm ...
随机推荐
- 浅析Json底层
在开始了解Json的原理之前,首先看一段代码,在这里以阿里的FastJson为例. public class JsonRun { public static void main(String[] ar ...
- django session 加密cookie型
a. 配置 settings.py SESSION_ENGINE = 'django.contrib.sessions.backends.signed_cookies' # 引 ...
- 【Android Studio】 加载so文件异常
AS无法加载so包异常 android studio导入so包异常:Couldn't load DeviceAPI from loader dalvik.system.PathClassLoader[ ...
- java.util.Queue
转载于:https://www.runoob.com/java/data-queue.html 队列是一种特殊的线性表,它只允许在表的前端进行删除操作,而在表的后端进行插入操作. LinkedList ...
- linux manual free memory
/proc/sys/vm/drop_caches (since Linux 2.6.16)Writing to this file causes the kernel to drop clean ca ...
- Jenkins发布.Net Core项目到IIS
安装Java8,Git,和Jenkins及插件. jenkins安装后以windows服务的方式运行,浏览器访问本机8080端口可访问. 自动部署的原理分为三步,首先从git服务器获取最新代码,然后用 ...
- 利用ant 执行jmeter用例生成html格式报告
1.安装ant 2.准备jmeter 及用例文件.jmx 3.编辑ant 执行文件build.xml <?xml version="1.0" encoding="G ...
- Java基础_类的加载机制和反射
类的使用分为三个步骤: 类的加载->类的连接->类的初始化 一.类的加载 当程序运行的时候,系统会首先把我们要使用的Java类加载到内存中.这里加载的是编译后的.class文件 每个类加载 ...
- CF1204A
CF1204A. BowWow and the Timetable 题意: 给你一个2进制数,求这个2进制数在10进制中的 $ 4^i $ 的个数. 解法: 其实就是 $ \ulcorner_{\lo ...
- 使用 suspend 和 resume 暂停和恢复线程
suspend 和 resume 的使用 在 Thread 类中有这样两个方法:suspend 和 resume,这两个方法是成对出现的. suspend() 方法的作用是将一个线程挂起(暂停), r ...