1,在servlet-dispatcher.xml中添加代码

<bean
id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver"
/>


也可以根据需求添加相关属性

<property name="maxUploadSize" value="2097152"></property> 
 

2,添加依赖jar文件

		<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>

3、编写uploadController

    @RequestMapping(value="/upload",method=RequestMethod.POST)
public String processUpload(@RequestParam("name") String name,
@RequestParam("file") MultipartFile file) throws IOException {
log.info("File '" + file.getOriginalFilename() + "' uploaded successfully");
if (!file.isEmpty()) {
try {
byte[] bytes = file.getBytes();
BufferedOutputStream stream =
new BufferedOutputStream(new FileOutputStream(new File(name)));
stream.write(bytes);
stream.close(); return "You successfully uploaded " + name + "!";
} catch (Exception e) {
return "You failed to upload " + name + " => " + e.getMessage();
}
} else {
return "You failed to upload " + name + " because the file was empty.";
}
}

4、使用RestClient测试上传


后台提示:

[2015-08-18 11/:36/:12]INFO  com.kaishuhezi.api.hardware.log.controller.LogController(line/:40) -File '78a0f7dcjw1e1bvyuzt1jj.jpg' uploaded successfully

Spring Uploading Files的更多相关文章

  1. Spring Configuration Check Unmapped Spring configuration files found

    Spring Configuration Check Unmapped Spring configuration files found 项目中有xml文件,但没有被用IntelliJ 导入现有工程时 ...

  2. 出现unmapped spring configuration files found

    intell idea启动出现unmapped spring configuration files found提示. 把spring里面的内容都打勾.

  3. IntelliJ IDEA 2017 提示“Unmapped Spring configuration files found.Please configure Spring facet.”解决办法

    当把自己的一个项目导入IDEA之后,Event Log提示“Unmapped Spring configuration files found.Please configure Spring face ...

  4. "Unmapped Spring configuration files found.Please configure Spring facet."解决办法

    最近在学习使用IDEA工具,觉得与Eclipse相比,还是有很多的方便之处. 但是,当把自己的一个项目导入IDEA之后,Event Log提示"Unmapped Spring configu ...

  5. Uploading Files in SharePoint 2013 using CSOM and REST

    http://www.shillier.com/archive/2013/03/26/uploading-files-in-sharepoint-2013-using-csom-and-rest.as ...

  6. IntelliJ 15 unmapped spring configuration files found

    IntelliJ Spring Configuration Check 用IntelliJ 导入现有工程时,如果原来的工程中有spring,每次打开工程就会提示:Spring Configuratio ...

  7. Uploading files using ASP.NET Web Api

    http://chris.59north.com/post/Uploading-files-using-ASPNET-Web-Api

  8. Unmapped Spring configuration files found.

    © 版权声明:本文为博主原创文章,转载请注明出处 1.问题描述: 搭建SSH框架后,IDEA弹出如下提示: 2.解决方案: File --> Project Structure --> M ...

  9. [转]Spring Boot修改最大上传文件限制:The field file exceeds its maximum permitted size of 1048576 bytes.

    来源:http://blog.csdn.net/awmw74520/article/details/70230591 SpringBoot做文件上传时出现了The field file exceeds ...

随机推荐

  1. Linux chmod命令具体解释

    仅仅能文件属主或特权用户才干使用该功能来改变文件存取模式.mode能够是数字形式或以who opcode permission形式表示. who是可选的,默认是a(全部用户). 仅仅能选择一个opco ...

  2. java类和对象的基础(笔记)

    在Java类的设计中,有时希望一个类在任何时候只能有一个实例.这时可以将该类设计为单例模式(singleton).要将一个类设计为单例模式,需要把类的构造方法的访问修饰符声明为private,然后在类 ...

  3. 【集训笔记】母函数【母函数模板】【HDOJ1028【HDOJ1085

    以下资料摘自 http://www.cnblogs.com/wally/archive/2012/07/13/hdu1028_1085_1171_.html 生成函数是说,构造这么一个多项式函数g(x ...

  4. 基于FPGA的DW8051移植(三)

    总结一下问题: 1) http://www.cnblogs.com/sepeng/p/4137405.html  基于FPGA的DW8051移植(一)里面用modelsim观测波形发现程序进入了ida ...

  5. mvc导航配置(View页面)

    @using Seyoit.Website.Config@using Seyoit.Website.Config.Navigation@{ var action = ViewContext.Route ...

  6. Python 2.7 学习笔记 面向对象的编程

    python是一种面向对象的语言.本文介绍如何用python进行面向对象的编程. 首先我们说下对象和类,类是一种类型的定义,对象是类的实例. 一.内置对象类型(内置类) 其实我们前面已经大量用到了对象 ...

  7. html中事件处理中的this和event对象

    在用js编写页面事件处理代码时,会经常涉及到this和event对象,但有时在采用不同的事件处理,尤其是在与自定义的对象关联时,这些对象的指向变的有些复杂. 本文来详细介绍下各种场景下 这些对象 真正 ...

  8. C++成员变量与函数内存分配

    关于结构体和C++类的内存地址问题 C++类是由结构体发展得来的,所以他们的成员变量(C语言的结构体只有成员变量)的内存分配机制是一样的.下面我们以类来说明问题,如果类的问题通了,结构体也也就没问题啦 ...

  9. 为什么我的outlook只能收信不能发信,发送测试电子邮件消息: 无法发送此邮件。请在帐户属性中验证电子邮件

    链接地址:http://zhidao.baidu.com/link?url=aVIFo2aNLuHIZGZuEUataHkZp4XApHqyvbEK8ACHPhi3jwhGhM0GBAtm72AnsP ...

  10. 排行榜妙用——CSS计数器

    碰到的坑 小伙伴你们是否有碰到以下的情况,排行榜前3名的样式不一样,你们是怎么处理的么?