diff --git a/src/main/java/com/zsz/config/SystemUtil.java b/src/main/java/com/zsz/config/SystemUtil.java index 4f534fb..d9b9e1c 100644 --- a/src/main/java/com/zsz/config/SystemUtil.java +++ b/src/main/java/com/zsz/config/SystemUtil.java @@ -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; } - - -} +} \ No newline at end of file