团队冲刺
今天协同陈少杰同学一起探索图片上传功能
基于昨天的路径设置,重新赋值给一个对象
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
public class Upload { static { System.out.println( "run this" ); } private static ApplicationContext applicationContext = new ClassPathXmlApplicationContext( "applicationContext.xml" ); private static ImgService imgService = (ImgService) applicationContext.getBean( "ImgServiceImpl" ); public static boolean uploadOne(MultipartFile file) { try { String path = CreatPath.creatPath(file); String hash = CreatPath.creatName(); String name = file.getOriginalFilename(); //上传文件的真实名称 String suffixName = name.substring(name.lastIndexOf( "." )); //获取后缀名 String fileName = hash + suffixName; File filepath = new File(path, fileName); ImgObject imgObject = new ImgObject(hash, path, name, staticConfig.UserMail, "nomal" ); imgService.addImg(imgObject); if (!filepath.getParentFile().exists()) { filepath.getParentFile().mkdirs(); } File tempFile = new File(path + fileName); file.transferTo(tempFile); return true ; } catch (Exception e) { return false ; } } } |