标签:tee nal image let 下载 springmvc exist str load
SpringMVC实现单文件上传
@RequestMapping("/uploadFile")
public String upload(@RequestParam(value="file") MultipartFile file,
HttpServletRequest request) throws IllegalStateException, IOException{
//如果文件不为空,写入上传路径
if(!file.isEmpty()) {
//上传文件绝对路径
String path = request.getServletContext().getRealPath("/images/");
//上传文件名
String filename = file.getOriginalFilename();
File filepath = new File(path,filename);
//判断路径是否存在,如果不存在就创建一个
if (!filepath.getParentFile().exists()) {
filepath.getParentFile().mkdirs();
}
//将上传文件保存到一个目标文件当中
file.transferTo(new File(path + File.separator + filename));
String showPath = request.getContextPath()+"/images/"+filename;
request.setAttribute("showPath", showPath);
return "hello";
} else {
return "error";
}
}
SpringMVC单文件下载
标签:tee nal image let 下载 springmvc exist str load
原文地址:https://www.cnblogs.com/strugglecola/p/8918756.html