UploadBiz.java
1.46 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.cjs.cms.biz.site;
import java.io.File;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
/**
* 上传图片公用
*
* @author 孔明可
*
*/
@Service
public class UploadBiz {
@Value("${upload.article}")
public String uploadPath;
// 上传服务器路径
@Value("${host}")
public String imageUrl;
// 创建图片存储文件夹
public Map<String, String> markFile() {
Calendar date = Calendar.getInstance();
String imageFile = "";
if (date.get(Calendar.MONTH) + 1 < 10) {
imageFile = uploadPath + date.get(Calendar.YEAR) + 0 + (date.get(Calendar.MONTH) + 1);
} else {
imageFile = uploadPath + date.get(Calendar.YEAR) + (date.get(Calendar.MONTH) + 1);
}
File file = new File(imageFile);
if (!file.exists() && file.isDirectory()) {
file.mkdir();
}
String host = "";
if (date.get(Calendar.MONTH) + 1 < 10) {
host = imageUrl + "img/" + date.get(Calendar.YEAR) + 0 + (date.get(Calendar.MONTH) + 1);
} else {
host = imageUrl + "img/" + date.get(Calendar.YEAR) + (date.get(Calendar.MONTH) + 1);
}
Map<String, String> map = new HashMap<String, String>();
map.put("uploadPath", imageFile);
map.put("imageUrl", host);
return map;
}
}