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. uva - The Lottery(容斥,好题)

    10325 - The Lottery The Sports Association of Bangladesh is in great problem with their latest lotte ...

  2. grub2的/etc/grub.d目录下的脚本文件

    00_header,05_debian_theme,10_linux,20_memtest86+,30_os- prober,40_custom这五个脚本对应grub.cfg上的各个部分,有的版本的g ...

  3. C#构架之基础学习----动态添加窗体和 控件

    仿照窗体应用程序编写: 任务一:生成一个Form类的窗体对象frm using System.Windows.Forms;         //using指令使用Form对象创建所需的命名空间 //如 ...

  4. Xcode插件(一)-规范注释生成器VVDocumenter

    原文来自:http://blog.csdn.net/hitwhylz/article/details/27813315 分享几个常用的Xcode插件. 第一个, 规范注释生成器VVDocumenter ...

  5. CentOS6.5下VNC Server远程桌面配置详解

    参考文献: (总结)CentOS Linux下VNC Server远程桌面配置详解 远程桌面连接工具VNC——license Key 我的下载地址为 太平洋下载 VNC连接黑屏的问题 centos 6 ...

  6. Android Matrix(坐标矩阵)

    Android Matrix 2016-02-26 14:38:10 介绍 中文名:坐标矩阵 高等数学里有介绍,在图像处理方面,主要是用于平面的缩放.平移.旋转等操作. 在Android里面,Matr ...

  7. JAVA平台上的网络爬虫脚本语言 CrawlScript

    JAVA平台上的网络爬虫脚本语言 CrawlScript 网络爬虫即自动获取网页信息的一种程序,有很多JAVA.C++的网络爬虫类库,但是在这些类库的基础上开发十分繁琐,需要大量的代码才可以完成一 个 ...

  8. 非确定有限状态自动机的构建(二)——将CharVal转换为NFA

    保留版权,转载注明出处:潘军彪的个人博客(http://blog.csdn.net/panjunbiao/article/details/9378933) 将上下文无关文法读入内存之后,可以将它转换成 ...

  9. 【四】注入框架RoboGuice使用:(Your First System Service Injection)

    上一篇我们简单的介绍了一下RoboGuice的使用([三]注入框架RoboGuice使用:(Your First Resource Injection)),今天我们来看下系统服务的使用注解的方法: 为 ...

  10. winform判断输入是否是数字

    private bool IsNum(string str) { try { foreach (char c in str) { if (char.IsDigit(c)) return true; r ...