spring 上传图片
@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 上传图片的更多相关文章
- spring mvc 的上传图片是怎么实现的?
spring mvc 的上传图片是怎么实现的? 导入jar包,commons-io.jar 及 commons-fileupload.jar 在springmvc的配置文件中配置Mutipart解析器 ...
- 利用Spring MVC 上传图片文件
本文转自:http://amcucn.iteye.com/blog/264457.感谢作者 近日在工作当中,需要用到上传图片的功能,然而自己平时学习的时候只会使用struts的上传功能,但因为项目并没 ...
- Spring Boot 上传图片文件
步骤一:基于前面springboot入门小demo 基于的springboot入门小demo,已包含了前面文章的知识点(比如:热部署.全局异常处理器). 步骤二:创建uploadPage.jsp上传页 ...
- jquery.uploadify+spring mvc实现上传图片
一.前端页面 1.下载jquery.uploadify 去uploadify官网(http://www.uploadify.com/download/)下载压缩包,解压后放在如下路径: 2.html结 ...
- Spring MVC -- UEditor 编辑器整合 上传图片至外部文件夹(非项目文件夹)
上传图片到外部储存,回显图片 下载全部UEditor资源源码 config.json配置 config.json中添加如下属性 (一定要添加此属性): "physicsPath": ...
- 使用cropper插件裁剪并上传图片(Spring mvc)
cropper是一款使用简单且功能强大的图片剪裁jQuery插件.该图片剪裁插件支持图片放大缩小,支持图片旋转,支持触摸屏设备,支持canvas,并且支持跨浏览器使用. cropper有两种方式上传截 ...
- spring mvc上传图片
1.需要commons-fileupload.jar commons-io.jar 2.需要在springmvc.xml中 配置存放静态资源的路径,对图片等静态资源放行 <mvc:resourc ...
- spring mvc 在上传图片时,浏览器报The request sent by the client was syntactically incorrect
项目中,在一个jsp页面里其它图片上传是功能是可以使用的,当我自己新加了一个图片上传时,提交表单后,浏览器报The request sent by the client was syntactical ...
- HTML5+Java(Spring下) 拍照上传图片
使用支持html5的浏览器,找个有摄像头,再建一个文件接收base64字串的图片然后保存就哦了 <html> <head runat="ReYo-Server"& ...
随机推荐
- myeclipse10 如何把代码预览的窗口去掉
1,选择菜单: windows -> preferences2,在弹出窗口中选择General-> Editors -> FileAssociations3,在上方框内选择*.jsp ...
- var_export函数的使用方法
var_export() 函数返回关于传递给该函数的变量的结构信息,它和 var_dump() 类似,不同的是其返回的表示是合法的 PHP 代码.var_export必须返回合法的php代码, 也就是 ...
- 数据库语句union的总结
select * from ( (select * from user limit 0,3) union (select * from user limit 10,30) ) tmp where ui ...
- BZOJ 2436 NOI嘉年华(单调优化)
http://www.lydsy.com/JudgeOnline/problem.php?id=2436 题意:两个会场不能同时表演,但是同一个时间可以同时表演,要求让两个会场表演数量最小的最大,然后 ...
- 暴力破解UltraEdit v21 无需注册
一.复制一份UltraEdit安装目录中的主程序uedit32.exe,到任意目录,用UltraEdit打开复制的uedit32.exe文件. 二.修改以下内容 原来:00094750h: BE DC ...
- ps2keyboard demo code for 8052
#pragma code symbols debug objectextend #include <reg51.h> /* special function register declar ...
- InnoSetup中枚举出INI文件的所有sections和键值
原文 http://blog.chinaunix.net/uid-23480430-id-3016899.html InnoSetup支持一些INI文件操作函数, 例如GetIniString,Ini ...
- jquery UI推荐
Bootstrap http://www.bootcss.com/ http://www.ligerui.com/ http://j-ui.com/#demo_page2 http://jqueryu ...
- 解决Struts2.2.20版本的标签不支持style属性的问题
我先把Exception错误信息贴出来:org.apache.jasper.JasperException: /WEB-INF/jsp/topicAction/addUI.jsp (line: 40, ...
- JSplitPane详解
摘自http://blog.163.com/xiexueyong1987@126/blog/static/1262673422010102711295541/ JSplitPane详解 pasting ...