@RequestMapping(value = "/upload",method = RequestMethod.POST)
public String upload(@RequestParam(value = "file", required = false) MultipartFile file){
// 判断文件是否为空
if (!file.isEmpty()) {
// 文件保存路径
String filePath = request.getSession().getServletContext().getRealPath("/") + "upload/"+ file.getOriginalFilename(); UUID uuid = UUID.randomUUID(); String filename = uuid + file.getOriginalFilename();
File targetFile = new File(filePath,filename);
if (!targetFile.exists()) { try {
targetFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
// 转存文件
try {
file.transferTo(targetFile);
} catch (IOException e) {
e.printStackTrace();
} }
return "upload";
}

spring 上传图片的更多相关文章

  1. spring mvc 的上传图片是怎么实现的?

    spring mvc 的上传图片是怎么实现的? 导入jar包,commons-io.jar 及 commons-fileupload.jar 在springmvc的配置文件中配置Mutipart解析器 ...

  2. 利用Spring MVC 上传图片文件

    本文转自:http://amcucn.iteye.com/blog/264457.感谢作者 近日在工作当中,需要用到上传图片的功能,然而自己平时学习的时候只会使用struts的上传功能,但因为项目并没 ...

  3. Spring Boot 上传图片文件

    步骤一:基于前面springboot入门小demo 基于的springboot入门小demo,已包含了前面文章的知识点(比如:热部署.全局异常处理器). 步骤二:创建uploadPage.jsp上传页 ...

  4. jquery.uploadify+spring mvc实现上传图片

    一.前端页面 1.下载jquery.uploadify 去uploadify官网(http://www.uploadify.com/download/)下载压缩包,解压后放在如下路径: 2.html结 ...

  5. Spring MVC -- UEditor 编辑器整合 上传图片至外部文件夹(非项目文件夹)

    上传图片到外部储存,回显图片 下载全部UEditor资源源码 config.json配置 config.json中添加如下属性 (一定要添加此属性): "physicsPath": ...

  6. 使用cropper插件裁剪并上传图片(Spring mvc)

    cropper是一款使用简单且功能强大的图片剪裁jQuery插件.该图片剪裁插件支持图片放大缩小,支持图片旋转,支持触摸屏设备,支持canvas,并且支持跨浏览器使用. cropper有两种方式上传截 ...

  7. spring mvc上传图片

    1.需要commons-fileupload.jar commons-io.jar 2.需要在springmvc.xml中 配置存放静态资源的路径,对图片等静态资源放行 <mvc:resourc ...

  8. spring mvc 在上传图片时,浏览器报The request sent by the client was syntactically incorrect

    项目中,在一个jsp页面里其它图片上传是功能是可以使用的,当我自己新加了一个图片上传时,提交表单后,浏览器报The request sent by the client was syntactical ...

  9. HTML5+Java(Spring下) 拍照上传图片

    使用支持html5的浏览器,找个有摄像头,再建一个文件接收base64字串的图片然后保存就哦了 <html> <head runat="ReYo-Server"& ...

随机推荐

  1. eclipse 添加jar包的方式

    参考资料地址:http://blog.csdn.net/mazhaojuan/article/details/21403717

  2. JS小数位保留两位小数--toFixed()

    parseInt,parseFloat,parseDouble在JS中是将值转换成相应的类型: 你必须要这样,才能实现: <script>         alert(parseFloat ...

  3. 【Nutch2.2.1源代码分析之4】Nutch加载配置文件的方法

    小结: (1)在nutch中,一般通过ToolRunner来运行hadoop job,此方法可以方便的通过ToolRunner.run(Configuration conf,Tool tool,Str ...

  4. python3.4入门——核心数据类型

    变量.对象和引用 变量的创建:一个变量(即变量名,如a),当代码第一次给它赋值就创建了它. 变量类型:变量没有任何和它关联的类型信息约束.类型的概念存在于对象中,而不是变量名中.变量原本是通用的,只是 ...

  5. 图铭Android平台银行卡号识别系统

    随着智能终端(智能手机及平板电脑)及移动通信(3G)的发展,原来运行在PC上的信息系统(如邮件系统.即时通信.网页浏览.协同办公.网络购物.社交网站.博客等)逐渐转移到智能终端设备上.可以预见未来几年 ...

  6. tessnet2 在vs2010 及以上版本不能调用的解决方案

    <startup useLegacyV2RuntimeActivationPolicy="true"> <supportedRuntime version=&qu ...

  7. Windows 8.1 with Update 镜像下载(增OEM单语言版)

    该系统已有更新的版本,请转至<Windows 8.1 with update 官方最新镜像汇总>下载. 2014年4月9日凌晨,微软向MSDN订阅用户开放了Windows 8.1 with ...

  8. 10.1.5 Connection Character Sets and Collations

    10.1.5 Connection Character Sets and Collations Several character set and collation system variables ...

  9. Openstack REST API

    There are some high quality resources that already cover the OpenStack API, so this is a YEA (yet an ...

  10. 一个sigaction的C++ wrap

    在上一篇文章(http://www.cnblogs.com/coding-my-life/p/4220128.html)中,提到了libev提供了处理信号的C++ wrap.但我显然接受不了需要进入l ...