拆分模块
This commit is contained in:
35
server/src/main/java/com/ecep/contract/MyProperties.java
Normal file
35
server/src/main/java/com/ecep/contract/MyProperties.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package com.ecep.contract;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "my")
|
||||
public class MyProperties {
|
||||
@Getter
|
||||
@Setter
|
||||
private String downloadsPath;
|
||||
|
||||
|
||||
/**
|
||||
* 尝试返回当前用户的下载文件夹
|
||||
*/
|
||||
public File getDownloadDirectory() {
|
||||
String downloadsPath = getDownloadsPath();
|
||||
if (StringUtils.hasText(downloadsPath)) {
|
||||
return new File(downloadsPath);
|
||||
}
|
||||
|
||||
// 没有配置下载目录时,尝试使用默认设置
|
||||
String home = System.getProperty("user.home");
|
||||
Path path = Paths.get(home, "Downloads");
|
||||
return path.toFile();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user