1、新建配置类
prefix值对应项目前缀
@Component
@ConfigurationProperties(prefix = "file")
public class SenseConfig {
/** 上传路径 */
private static String uploadFilePath;
/** 上传路径-windows */
private static String uploadWindowsFilePath;
/** 上传路径-linux */
private static String uploadLinuxFilePath;
/** 获取地址开关 */
private static boolean addressEnabled;
public static boolean isAddressEnabled() {
return addressEnabled;
}
public void setAddressEnabled(boolean addressEnabled) {
SenseConfig.addressEnabled = addressEnabled;
}
public static String getUploadFilePath() {
return uploadFilePath;
}
public void setUploadWindowsFilePath(String uploadWindowsFilePath) {
SenseConfig.uploadWindowsFilePath = uploadWindowsFilePath;
//获取当前操作系统类型
String os = System.getProperty("os.name").toLowerCase();
if (os.indexOf("windows") != -1) {
uploadFilePath = SenseConfig.uploadWindowsFilePath;
}
}
public void setUploadLinuxFilePath(String uploadLinuxFilePath) {
SenseConfig.uploadLinuxFilePath = uploadLinuxFilePath;
String os = System.getProperty("os.name").toLowerCase();
if (os.indexOf("windows") == -1) {
uploadFilePath = SenseConfig.uploadLinuxFilePath;
}
}
}
配置文件中配置文件上传位置: