From 1d334cda1cb6a945c266aa5493e457824f360de4 Mon Sep 17 00:00:00 2001 From: PineappleLB <31363497+PineappleLB@users.noreply.github.com> Date: Mon, 29 Jul 2019 16:44:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BB=8Espring=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E4=B8=AD=E8=AF=BB=E5=8F=96=E9=85=8D=E7=BD=AE=E7=9A=84?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E7=B1=BB=EF=BC=8C=E6=96=B9=E4=BE=BF=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E5=A4=9A=E7=8E=AF=E5=A2=83=E6=88=96=E8=80=85=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E4=BB=8E=E5=90=AF=E5=8A=A8=E5=91=BD=E4=BB=A4=E4=B8=AD?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/config/EnvironmentConfig.java | 148 ++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/config/EnvironmentConfig.java diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/config/EnvironmentConfig.java b/ruoyi-common/src/main/java/com/ruoyi/common/config/EnvironmentConfig.java new file mode 100644 index 000000000..a9ee0ca8f --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/config/EnvironmentConfig.java @@ -0,0 +1,148 @@ +package com.ruoyi.common.config; + +import com.ruoyi.common.utils.StringUtils; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; + +/** + * 从spring配置变量中获取属性值 + * @author pineapple + * @date 2019-07-29 + * @email 2443755705@qq.com + */ +@Component +public class EnvironmentConfig implements ApplicationContextAware { + + private static ApplicationContext context; + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + EnvironmentConfig.context = applicationContext; + } + + public static String getConfig(String key) { + return context.getEnvironment().getProperty(key); + } + + public static String getConfig(String key, String defaultValue) { + return context.getEnvironment().getProperty(key, defaultValue); + } + + public static T getConfig(String key, Class clazz) { + return context.getEnvironment().getProperty(key, clazz); + } + + public static T getConfig(String key, Class clazz, T defaultValue) { + return context.getEnvironment().getProperty(key, clazz, defaultValue); + } + + /** + * 获取项目名称 + */ + public String getName() + { + return StringUtils.nvl(getConfig("ruoyi.name"), "RuoYi"); + } + + /** + * 获取项目版本 + */ + public String getVersion() + { + return StringUtils.nvl(getConfig("ruoyi.version"), "3.2.0"); + } + + /** + * 获取版权年份 + */ + public String getCopyrightYear() + { + return StringUtils.nvl(getConfig("ruoyi.copyrightYear"), "2018"); + } + + /** + * 获取ip地址开关 + */ + public Boolean isAddressEnabled() + { + return Boolean.valueOf(getConfig("ruoyi.addressEnabled")); + } + + /** + * 获取文件上传路径 + */ + public String getProfile() + { + return getConfig("ruoyi.profile"); + } + + /** + * 获取头像上传路径 + */ + public String getAvatarPath() + { + return getConfig("ruoyi.profile") + "avatar/"; + } + + /** + * 获取下载路径 + */ + public String getDownloadPath() + { + //下载目录 + // return getConfig("ruoyi.profile") + "download/"; + + return getConfig("ruoyi.profile") + "upload/"; + } + + public String seeProfile() + { + //下载目录 + // return getConfig("ruoyi.profile") + "download/"; + + return getConfig("ruoyi.seeProfile"); + } + + /** + * 获取上传路径 + */ + public String getUploadPath() + { + return getConfig("ruoyi.profile") + "upload/"; + } + + /** + * 获取作者 + */ + public String getAuthor() + { + return StringUtils.nvl(getConfig("gen.author"), "ruoyi"); + } + + /** + * 生成包路径 + */ + public String getPackageName() + { + return StringUtils.nvl(getConfig("gen.packageName"), "com.ruoyi.project.module"); + } + + /** + * 是否自动去除表前缀 + */ + public String getAutoRemovePre() + { + return StringUtils.nvl(getConfig("gen.autoRemovePre"), "true"); + } + + /** + * 表前缀(类名不会包含表前缀) + */ + public String getTablePrefix() + { + return StringUtils.nvl(getConfig("gen.tablePrefix"), "sys_"); + } + +}