package io.renren.controller;
import io.renren.service.PictureService;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
@Controller
public class FileUpload {
@Autowired
PictureService pictureService;
/**
* 多个文件上传
*
* @param files
* @param model
* @return
*/
@RequestMapping("file/uploads")
public String upload(@RequestParam("file") CommonsMultipartFile files[],
ModelMap model) {
List<Map<String, String>> list = pictureService.upload(files);
model.addAttribute("list", list);
return "forward:/mulitFile.jsp";
}
/**
* 异步上传处理
*
* @param request
* @param response
* @param file
* @return 返回上传文件相对路径及名称
* @throws IOException
*/
@RequestMapping(value = "file/upload", produces = "text/json;charset=UTF-8")
@ResponseBody
public Map<String, String> uploadFileHandler(HttpServletRequest request,
@RequestParam("file") MultipartFile file) {
Map<String, String> map = new HashMap<String, String>();
// 上传文件每日单独保存
String path = "upload/";
if (file.getSize() > 0) {
// 获取绝对路径
String uploadPath = request.getSession().getServletContext()
.getRealPath(path);
try {
// 创建目标文件
File targetFile = new File(uploadPath,
file.getOriginalFilename());
if (!targetFile.exists()) {
targetFile.mkdirs();
}
file.transferTo(targetFile);
map.put("msg", path + file.getOriginalFilename());
map.put("code", "200");
return map;
} catch (Exception e) {
e.printStackTrace();
map.put("msg", "保存文件失败");
}
} else {
map.put("msg", "请选择一个文件上传");
}
return map;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
带进度和多文件上传,基于ssm
共50个文件
xml:10个
java:9个
class:9个
1星 需积分: 9 76 下载量 175 浏览量
2017-04-20
16:26:50
上传
评论 3
收藏 98KB ZIP 举报
温馨提示
带进度的文件上传和多文件上传.spring是4.0的.工具是myeclipse.项目是完整源码,可以直接运行
资源推荐
资源详情
资源评论
收起资源包目录
file.zip (50个子文件)
news
.project 2KB
.mymetadata 293B
src
test
resources
java
main
webapp
WEB-INF
lib
page
web.xml 2KB
dispatcher-servlet.xml 324B
index.jsp 4KB
plugins
demo
bootstrap.min.css 118KB
bootstrap.min.js 36KB
demo.js 581B
jquery
jquery.min.js 84KB
mulitFile.jsp 1KB
META-INF
MANIFEST.MF 39B
resources
spring-renren.xml 371B
spring-mvc.xml 2KB
java
io
renren
service
PictureService.java 266B
impl
PictureServiceImp.java 2KB
utils
FileUtil.java 498B
DateUtils.java 1KB
CustomMultipartResolver.java 2KB
FileUploadProgressListener.java 705B
controller
PageController.java 312B
FileUpload.java 2KB
dao
entity
ProgressBean.java 788B
target
m2e-jee
web-resources
META-INF
MANIFEST.MF 105B
maven
com.news
news
pom.properties 227B
pom.xml 6KB
com.demo
demo
pom.properties 227B
pom.xml 6KB
classes
spring-renren.xml 371B
io
renren
service
PictureService.class 391B
impl
PictureServiceImp.class 3KB
utils
CustomMultipartResolver.class 3KB
DateUtils.class 1KB
FileUtil.class 1KB
FileUploadProgressListener.class 1KB
controller
FileUpload.class 4KB
PageController.class 590B
dao
entity
ProgressBean.class 1KB
spring-mvc.xml 2KB
test-classes
.settings
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.common.project.facet.core.xml 252B
org.eclipse.m2e.core.prefs 90B
com.genuitec.eclipse.core.prefs 120B
org.eclipse.jdt.core.prefs 430B
org.eclipse.wst.jsdt.ui.superType.name 6B
com.genuitec.eclipse.j2eedt.core.prefs 56B
org.eclipse.core.resources.prefs 165B
org.eclipse.wst.common.component 563B
.jsdtscope 508B
pom.xml 6KB
.classpath 861B
共 50 条
- 1
资源评论
- 人面不知何处去-2018-05-03骗人的,,,,,,,,
老乡zx
- 粉丝: 8
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功