• 大小: 1.7MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-09-02
  • 语言: Java
  • 标签: java  图片上传  

资源简介

该demo是用前端的一个图片上传插件,自己写的后台处理使用ssm,能对图片上传处理并将路径回显到界面,demo中没有对数据库做操作只做了简单显示处理。使用的开发环境为eclipse当前最新javaEE版本,使用maven搭建的ssm,jdk1.8 64位。

资源截图

代码片段和文件信息

package controller;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping(“upload“)
public class UploadCotroller {

private final String IMAGE_UPLOAD_PATH = “f:\\“+File.separator+“wl“+File.separator+“temp“;

@RequestMapping(“/openAddView.do“)
public ModelAndView openAddView() {
ModelAndView mv = new ModelAndView();
mv.setViewName(“addView“);
return mv;
}

@RequestMapping(“/image.do“)
public void upload(@RequestParam(“fileList“) MultipartFile fileListHttpServletResponse resp){
try {
String filePath = ““;
filePath = IMAGE_UPLOAD_PATH+File.separator+getUniqueFileName(fileList.getOriginalFilename());
File file = new File(filePath);
fileList.transferTo(file);
resp.setCharacterEncoding(“UTF-8“);
resp.getWriter().write(filePath+“;“);
} catch (IllegalStateException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

private String getUniqueFileName(String originalFileName) {
String ext = originalFileName.substring(originalFileName.lastIndexOf(“.“)originalFileName.length());
String originalPrefixFileName = originalFileName.substring(0originalFileName.lastIndexOf(“.“));
UUID uuid = UUID.randomUUID();
String uniqueFileName = originalPrefixFileName+uuid+ext;
return uniqueFileName;
}
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-05-07 22:47  imageUploadDemo\
     文件        1401  2017-05-07 20:03  imageUploadDemo\.classpath
     文件        1091  2017-05-05 22:41  imageUploadDemo\.project
     目录           0  2017-05-07 22:47  imageUploadDemo\.settings\
     文件         639  2017-05-05 22:41  imageUploadDemo\.settings\.jsdtscope
     文件         430  2017-05-05 22:41  imageUploadDemo\.settings\org.eclipse.jdt.core.prefs
     文件          90  2017-05-05 22:41  imageUploadDemo\.settings\org.eclipse.m2e.core.prefs
     文件         602  2017-05-05 22:44  imageUploadDemo\.settings\org.eclipse.wst.common.component
     文件         252  2017-05-05 22:41  imageUploadDemo\.settings\org.eclipse.wst.common.project.facet.core.xml
     文件          49  2017-05-05 22:41  imageUploadDemo\.settings\org.eclipse.wst.jsdt.ui.superType.container
     文件           6  2017-05-05 22:41  imageUploadDemo\.settings\org.eclipse.wst.jsdt.ui.superType.name
     文件          50  2017-05-05 22:41  imageUploadDemo\.settings\org.eclipse.wst.validation.prefs
     文件        4999  2017-05-07 19:48  imageUploadDemo\pom.xml
     目录           0  2017-05-07 22:47  imageUploadDemo\src\
     目录           0  2017-05-07 22:47  imageUploadDemo\src\main\
     目录           0  2017-05-07 22:47  imageUploadDemo\src\main\java\
     目录           0  2017-05-07 22:47  imageUploadDemo\src\main\java\controller\
     文件        1723  2017-05-07 22:38  imageUploadDemo\src\main\java\controller\UploadCotroller.java
     目录           0  2017-05-07 22:57  imageUploadDemo\src\main\java\dao\
     目录           0  2017-05-07 22:57  imageUploadDemo\src\main\java\entity\
     文件        2391  2017-05-07 20:37  imageUploadDemo\src\main\java\generatorConfig.xml
     目录           0  2017-05-07 22:57  imageUploadDemo\src\main\java\mapper\
     目录           0  2017-05-07 22:57  imageUploadDemo\src\main\java\service\
     目录           0  2017-05-07 22:47  imageUploadDemo\src\main\resources\
     文件         277  2017-05-07 21:15  imageUploadDemo\src\main\resources\jdbc.properties
     文件         925  2017-05-07 19:44  imageUploadDemo\src\main\resources\log4j.properties
     文件        2524  2017-05-07 21:25  imageUploadDemo\src\main\resources\spring-mvc.xml
     文件        2689  2017-05-07 21:22  imageUploadDemo\src\main\resources\spring-mybatis.xml
     目录           0  2017-05-07 22:47  imageUploadDemo\src\main\webapp\
     目录           0  2017-05-07 22:47  imageUploadDemo\src\main\webapp\WEB-INF\
     目录           0  2017-05-07 22:57  imageUploadDemo\src\main\webapp\WEB-INF\classes\
............此处省略196个文件信息

评论

共有 条评论