Update SystemUtil.java

main
pveayojnc 4 months ago
parent fe221430c6
commit 6ef529c891

@ -4,53 +4,66 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
/**
* @author : Mingxuan_x
* @version : 1.0
* @Description:
* @Telephone : 15135964789
* @createDate : 2021/4/11 14:38
* @updateUser : Mingxuan_x
* @updateDate : 2021/4/11 14:38
* @updateRemark :
**/
@Component
*
*
*
* @author Mingxuan_x
* @version 1.0
* @Telephone 15135964789
* @createDate 2021/4/11 14:38
* @updateUser Mingxuan_x
* @updateDate 2021/4/11 14:38
* @updateRemark
*/
@Component // 声明为Spring组件由Spring容器管理
public class SystemUtil {
@Value("${file.upload.windows.dir}")
// Windows系统文件上传路径从配置文件中注入
@Value("${file.upload.windows.dir}")
private String windowsPath;
// Linux系统文件上传路径从配置文件中注入
@Value("${file.upload.linux.dir}")
private String linuxPath;
// Mac系统文件上传路径从配置文件中注入
@Value("${file.upload.mac.dir}")
private String macPath;
private final String LINUX = "linux";
private final String WINDOWS = "windows";
// 操作系统类型常量
private static final String LINUX = "linux";
private static final String WINDOWS = "windows";
/**
*
*
* @return:
* @Author: Mingxuan_X
* @Date: 2021/4/11
*
*
*
* 1.
* 2. linux/windows
* 3.
* 4. mac
*
* @return String
* @Author Mingxuan_X
* @Date 2021/4/11
*/
public String getFilePrefix() {
String s = null;
//判断操作系统环境
String environment = System.getProperty("os.name").toLowerCase();
if (environment.contains(LINUX)) {
s = linuxPath;
} else if (environment.contains(WINDOWS)) {
s = windowsPath;
String systemPath = null;
// 获取操作系统名称并转为小写例如Windows 10 → windows 10
String osName = System.getProperty("os.name").toLowerCase();
// 根据操作系统类型选择对应的路径配置
if (osName.contains(LINUX)) {
systemPath
= linuxPath; // Linux系统路径
} else if (osName.contains(WINDOWS)) {
systemPath
= windowsPath; // Windows系统路径
} else {
s = macPath;
systemPath
= macPath; // 其他系统主要是Mac路径
}
return s;
return systemPath;
}
}
}
Loading…
Cancel
Save