资源简介
ssm框架实现的文件上传,自带数据库脚本,使用的是mysql,开发工具是myeclipse,简单操作,readme,有详细介绍。一看就会。

代码片段和文件信息
package com.ren.controller;
import java.io.File;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import com.ren.entity.Users;
import com.ren.service.UserService;
/**
* 文件上传控制类
* @author Administrator
*
*/
@Controller
public class FileController2 {
@Autowired
private UserService userService;
Users user =new Users();
@RequestMapping(“/upload.do“)
public String queryFileData(@RequestParam(“uploadfile“) CommonsMultipartFile fileHttpServletRequest request) {
//判断上传的文件是否为空
if (!file.isEmpty()) {
//文件的真实名称
String realFilename = file.getOriginalFilename();
//获取文件格式后缀名
String type = file.getOriginalFilename().substring(file.getOriginalFilename().indexOf(“.“));
// 取当前时间戳作为文件名
String filename = System.currentTimeMillis() + type;
String path = request.getSession().getServletContext().getRealPath(“/upload/“ + filename);// 存放位置
File destFile = new File(path);
try {
//有时候你的copyInputStreamToFile会报错,这时候就要看看你的上传文件的jar包是否符合
//刚开始有人汇报说报红线,其实都是版本过低了,建议用我的jar包
FileUtils.copyInputStreamToFile(file.getInputStream() destFile);// 复制临时文件到指定目录下
} catch (IOException e) {
e.printStackTrace();
}
user.setName(filename);
user.setPath(path);
user.setRealFilename(realFilename);
userService.upload_photo(user);
return “redirect:success.jsp“;
} else {
return “redirect:fail.jsp“;
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-06-09 13:54 test_upload1\
文件 1093 2018-06-09 10:43 test_upload1\.classpath
文件 1337 2018-06-09 10:51 test_upload1\.project
目录 0 2018-06-09 13:54 test_upload1\.settings\
文件 522 2018-06-09 10:43 test_upload1\.settings\.jsdtscope
文件 108 2018-06-09 10:46 test_upload1\.settings\com.genuitec.eclipse.core.prefs
文件 364 2018-06-09 10:43 test_upload1\.settings\org.eclipse.jdt.core.prefs
文件 495 2018-06-09 10:43 test_upload1\.settings\org.eclipse.wst.common.component
文件 414 2018-06-09 10:43 test_upload1\.settings\org.eclipse.wst.common.project.facet.core.xm
文件 49 2018-06-09 10:43 test_upload1\.settings\org.eclipse.wst.jsdt.ui.superType.container
文件 6 2018-06-09 10:43 test_upload1\.settings\org.eclipse.wst.jsdt.ui.superType.name
目录 0 2018-06-09 13:54 test_upload1\src\
目录 0 2018-06-09 13:54 test_upload1\src\com\
目录 0 2018-06-09 13:54 test_upload1\src\com\ren\
目录 0 2018-06-09 13:54 test_upload1\src\com\ren\controller\
文件 2028 2018-06-09 13:39 test_upload1\src\com\ren\controller\FileController2.java
目录 0 2018-06-09 13:54 test_upload1\src\com\ren\dao\
文件 187 2018-06-09 13:39 test_upload1\src\com\ren\dao\UserDao.java
文件 311 2018-06-09 13:31 test_upload1\src\com\ren\dao\UserDaoMapper.xm
目录 0 2018-06-09 13:54 test_upload1\src\com\ren\entity\
文件 678 2018-06-09 13:39 test_upload1\src\com\ren\entity\Users.java
目录 0 2018-06-09 13:54 test_upload1\src\com\ren\service\
目录 0 2018-06-09 13:54 test_upload1\src\com\ren\service\impl\
文件 593 2018-06-09 13:40 test_upload1\src\com\ren\service\impl\UserServiceImpl.java
文件 197 2018-06-09 13:40 test_upload1\src\com\ren\service\UserService.java
文件 99 2018-06-09 13:07 test_upload1\src\jdbc.properties
文件 2422 2018-06-09 13:33 test_upload1\src\spring-mvc.xm
文件 2211 2018-06-09 12:59 test_upload1\src\spring.xm
目录 0 2018-06-09 13:54 test_upload1\WebRoot\
文件 837 2018-06-09 11:29 test_upload1\WebRoot\fail.jsp
文件 829 2018-06-09 10:43 test_upload1\WebRoot\index.jsp
............此处省略48个文件信息
相关资源
- Spring+Struts2+Hibernate人力资源管理系统
- 东城大学在线答疑系统struts2+spring带
- Maven搭建Spring+Mybatis+MySql
- SSH+Spring Security+MySQL
- Struts、Hibernate、Spring框架SSH框架整合
- Spring MVC+MySQL框架直接使用
- springmvc+spring+mybatis+mysql数据库整合读
- 黑马 出品代码生成器
- 基于SpringBoot技术开发的个人博客系统
- 框架写的简单学生管理系统
- 基于SpringBoot2+Jpa+SpringSecurity+redis+Vue的
- SpringBoot测试项目
- oracle数据库 +springmvc框架 开发的增删
- 毕业设计体检预约系统-springmvc+mybat
- Springmvc+jdbc简单学生管理系统
- SpringBoot员工管理系统.7z
- springboot学生管理系统.zip
- Struts2+spring+Mybatis+mysql+架包相对完善的
- Ajax+SpringMVC+Spring+Mybatis+MySql+js用户注册
- 简易后台管理系统
- 用Struts2写的小程序用户注册,登录,
- 基于springmvc、spring、mybatis、shiro、e
- SpingMVC+MyBatis简单权限管理系统
- mvc图书管理系统作品sql数据库
- 基于SSH框架的微博实现
- Extjs+Mysql+SpringMVC+MyBatis通用后台管理系
- SpringBootLearning_forezp.tar.gz
- idea+springboot+oracle+mybatis
- SpringMVC+Mybatis+SQLServer整合源码 含数据
- 基于Springboot的药品管理系统.rar
评论
共有 条评论