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