Skip to content

Commit 9341c88

Browse files
juzi214032colorful3
authored andcommitted
refactor(Uploader): 重构文件上传配置信息获取方式
配置信息获取方式从 @value 修改为使用 FileProperties 实例获取
1 parent a9121bd commit 9341c88

2 files changed

Lines changed: 24 additions & 10 deletions

File tree

src/main/java/io/github/talelin/latticy/module/file/FileProperties.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@
33
import io.github.talelin.latticy.common.factory.YamlPropertySourceFactory;
44
import org.springframework.boot.context.properties.ConfigurationProperties;
55
import org.springframework.context.annotation.PropertySource;
6-
import org.springframework.core.annotation.Order;
76
import org.springframework.stereotype.Component;
87

98
/**
109
* @author pedro@TaleLin
1110
*/
1211
@Component
13-
@ConfigurationProperties(prefix = "lin.file")
12+
@ConfigurationProperties("lin.file")
1413
@PropertySource(
1514
value = "classpath:io/github/talelin/latticy/extension/file/config.yml",
16-
encoding = "UTF-8",factory = YamlPropertySourceFactory.class)
15+
encoding = "UTF-8", factory = YamlPropertySourceFactory.class)
1716
public class FileProperties {
1817

1918
private static final String[] DEFAULT_EMPTY_ARRAY = new String[0];
@@ -30,6 +29,19 @@ public class FileProperties {
3029

3130
private String[] include = DEFAULT_EMPTY_ARRAY;
3231

32+
/**
33+
* 文件存储路径
34+
*/
35+
private String servePath = "assets/**";
36+
37+
public String getServePath() {
38+
return servePath;
39+
}
40+
41+
public void setServePath(String servePath) {
42+
this.servePath = servePath;
43+
}
44+
3345
public String getStoreDir() {
3446
return storeDir;
3547
}

src/main/java/io/github/talelin/latticy/service/impl/FileServiceImpl.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import cn.hutool.core.bean.BeanUtil;
44
import io.github.talelin.latticy.bo.FileBO;
55
import io.github.talelin.latticy.module.file.FileConstant;
6+
import io.github.talelin.latticy.module.file.FileProperties;
67
import io.github.talelin.latticy.module.file.Uploader;
78
import io.github.talelin.latticy.mapper.FileMapper;
89
import io.github.talelin.latticy.model.FileDO;
@@ -19,18 +20,19 @@
1920

2021
/**
2122
* @author pedro@TaleLin
23+
* @author Juzi@TaleLin
2224
*/
2325
@Service
2426
public class FileServiceImpl extends ServiceImpl<FileMapper, FileDO> implements FileService {
2527

2628
@Autowired
2729
private Uploader uploader;
2830

29-
@Value("${lin.file.domain}")
30-
private String domain;
31-
32-
@Value("${lin.file.serve-path:assets/**}")
33-
private String servePath;
31+
/**
32+
* 文件上传配置信息
33+
*/
34+
@Autowired
35+
private FileProperties fileProperties;
3436

3537
/**
3638
* 为什么不做批量插入
@@ -67,8 +69,8 @@ private FileBO transformDoToBo(FileDO file, String key) {
6769
FileBO bo = new FileBO();
6870
BeanUtil.copyProperties(file, bo);
6971
if (file.getType().equals(FileConstant.LOCAL)) {
70-
String s = servePath.split("/")[0];
71-
bo.setUrl(domain + s + "/" + file.getPath());
72+
String s = fileProperties.getServePath().split("/")[0];
73+
bo.setUrl(fileProperties.getDomain() + s + "/" + file.getPath());
7274
} else {
7375
bo.setUrl(file.getPath());
7476
}

0 commit comments

Comments
 (0)