package com.util;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.springframework.web.multipart.MultipartFile;
import com.util.RandomNum;
public class Upload {
private String diskPath;
public Upload(String diskPath) {
if(!diskPath.endsWith("/")){
diskPath += "/";
}
this.diskPath = diskPath;
}
public String upload(String folder,String visitPath,MultipartFile... mf){
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
StringBuffer strb = new StringBuffer();
if(!"".equals(folder)){
if(!folder.endsWith("/")){
folder += "/";
}
}
for (int i = 0; i < mf.length; i++) {
if(mf[i].getSize() != 0){
String suffix = mf[i].getOriginalFilename().substring(mf[i].getOriginalFilename().lastIndexOf("."));
String fileName = format.format(new Date()) + RandomNum.getRandom(3) + suffix;
try {
mf[i].transferTo(new File(this.diskPath + folder + fileName));
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
strb.append("/"+visitPath+"/"+folder+fileName+";");
}
}
if(strb.length() != 0){
return strb.toString().substring(0, strb.length() - 1);
}
return null;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
SpringMVC_Upload.rar_shipvu7_springmvc_springmvc upload
共28个文件
xml:8个
class:3个
java:3个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 49 浏览量
2022-09-24
10:57:14
上传
评论
收藏 1.5MB RAR 举报
温馨提示
实现springmvc 多文件上传,可以获取返回值,进行数据库的操作
资源推荐
资源详情
资源评论
收起资源包目录
SpringMVC_Upload.rar (28个子文件)
SpringMVC_Upload
.springBeans 458B
.settings
com.genuitec.runtime.libraries.xml 108B
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.wst.common.project.facet.core.xml 446B
org.eclipse.wst.common.component 507B
org.eclipse.wst.common.project.facet.core.prefs.xml 588B
org.eclipse.wst.jsdt.ui.superType.container 49B
.jsdtscope 564B
org.eclipse.jdt.core.prefs 364B
src
springmvc.xml 1KB
com
controller
UploadDemo.java 865B
util
RandomNum.java 372B
Upload.java 1KB
applicationContext.xml 554B
.project 1KB
WebRoot
images
user
photo
META-INF
MANIFEST.MF 39B
WEB-INF
web.xml 1KB
classes
springmvc.xml 1KB
com
controller
UploadDemo.class 2KB
util
Upload.class 2KB
RandomNum.class 805B
applicationContext.xml 554B
lib
jackson-all-2.8.0.jar 1.43MB
commons-io-2.6.jar 210KB
spring.tld 18KB
spring-form.tld 74KB
index.jsp 1KB
.classpath 1KB
共 28 条
- 1
资源评论
alvarocfc
- 粉丝: 105
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功