public String uploading(HttpServletRequest request, @RequestParam("file1") MultipartFile file,Model model) throws IllegalStateException, IOException {
// ProducerTest producerTest = new ProducerTest();
//如果文件不为空,写入上传路径
if(!file.isEmpty()) {
//上传文件路径
String path = request.getServletContext().getRealPath("/files/");
//上传文件名
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));
}
}
spring-mvc.xml 配置
//加上maven 坐标
commons-fileupload
commons-fileupload
1.2.1
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)