package com.thinkgem.jeesite.common.config;

 import java.io.UnsupportedEncodingException;
import java.util.Map; import org.apache.commons.lang3.StringUtils;
import org.springframework.util.Assert; import com.google.common.collect.Maps;
import com.thinkgem.jeesite.common.utils.PropertiesLoader; /**
* 全局配置类
* @author ThinkGem
* @version 2013-03-23
*/
public class Global { /**
* 保存全局属性值
*/
private static Map<String, String> map = Maps.newHashMap(); /**
* 属性文件加载对象
*/
private static PropertiesLoader propertiesLoader = new PropertiesLoader("jeesite.properties"); /**
* 获取配置
*/
public static String getConfig(String key) {
return getConfig(key, null);
}
/**
* 获取配置
*/
public static String getConfig(String key, String defaultVal) {
String value = map.get(key);
if (value == null){
value = propertiesLoader.getProperty(key);
map.put(key, value);
}
if(StringUtils.isBlank(value)
&& StringUtils.isNotBlank(defaultVal) ){
return defaultVal;
}
return value;
} ///////////////////////////////////////////////////////// public static String getDataDownDbUser() {
return Global.getConfig("dataDownDbUser","NX_DOWN_DATA") ;
} /**
* 获取管理端根路径
*/
public static String getAdminPath() {
return getConfig("adminPath");
} /**
* 获取前端根路径
*/
public static String getFrontPath() {
return getConfig("frontPath");
} /**
* 获取URL后缀
*/
public static String getUrlSuffix() {
return getConfig("urlSuffix");
} /**
* 是否是演示模式,演示模式下不能修改用户、角色、密码、菜单、授权
*/
public static Boolean isDemoMode() {
String dm = getConfig("demoMode");
return "true".equals(dm) || "1".equals(dm);
} /**
* 获取CKFinder上传文件的根目录
* @return
*/
public static String getCkBaseDir() {
String dir = getConfig("userfiles.basedir");
Assert.hasText(dir, "配置文件里没有配置userfiles.basedir属性");
if(!dir.endsWith("/")) {
dir += "/";
}
return dir;
} }

简单的打包:

package com.thinkgem.jeesite.common.config;

import java.io.UnsupportedEncodingException;
import java.util.Map; import org.apache.commons.lang3.StringUtils;
import org.springframework.util.Assert; import com.google.common.collect.Maps;
import com.thinkgem.jeesite.common.utils.PropertiesLoader; public class Global { /**
* 保存全局属性值
*/
private static Map<String, String> map = Maps.newHashMap(); /**
* 属性文件加载对象
*/
private static PropertiesLoader propertiesLoader = new PropertiesLoader("jeesite.properties"); /**
* 获取配置
*/
public static String getConfig(String key) {
return getConfig(key, null);
}
/**
* 获取配置
*/
public static String getConfig(String key, String defaultVal) {
String value = map.get(key);
if (value == null){
value = propertiesLoader.getProperty(key);
map.put(key, value);
}
if(StringUtils.isBlank(value)
&& StringUtils.isNotBlank(defaultVal) ){
return defaultVal;
}
return value;
} ///////////////////////////////////////////////////////// public static String getDataDownDbUser() {
return Global.getConfig("dataDownDbUser","NX_DOWN_DATA") ;
} /**
* 获取管理端根路径
*/
public static String getAdminPath() {
return getConfig("adminPath");
} /**
* 获取前端根路径
*/
public static String getFrontPath() {
return getConfig("frontPath");
} /**
* 获取URL后缀
*/
public static String getUrlSuffix() {
return getConfig("urlSuffix");
} /**
* 是否是演示模式,演示模式下不能修改用户、角色、密码、菜单、授权
*/
public static Boolean isDemoMode() {
String dm = getConfig("demoMode");
return "true".equals(dm) || "1".equals(dm);
} /**
* 获取CKFinder上传文件的根目录
* @return
*/
public static String getCkBaseDir() {
String dir = getConfig("userfiles.basedir");
Assert.hasText(dir, "配置文件里没有配置userfiles.basedir属性");
if(!dir.endsWith("/")) {
dir += "/";
}
return dir;
} }

调用示例:

Global.getDataDownDbUser();

java jeesite.properties配置文件属性提取的更多相关文章

  1. java 读写properties (配置)文件

    Properties属性文件在Java应用程序中是经常可以看得见的,也是特别重要的一类文件.它用来配置应用程序的一些信息,不过这些信息一般都是比较少的数据,没有必要使用数据库文件来保存,而使用一般的文 ...

  2. 获取.properties配置文件属性值

    public class TestProperties { /** * * @Title: printAllProperty * @Description: 输出所有配置信息 * @param pro ...

  3. java Properties 配置信息类

    Properties(配置信息类):主要用于生产配置文件和读取配置文件信息. ----> 是一个集合类 继承HashTable 存值是以键-值的方式. package com.beiwo.io; ...

  4. java读取properties文件的配置信息

    项目开发中,我们一般来向 application.properties 文件中放一些全局配置变量,以便程序中读取使用,本篇内容来演示从properties配置文件中读取键值. 当然,我们不一定写入 a ...

  5. JAVA加载Properties配置资源文件

    JAVA加载Properties配置资源文件 制作人:全心全意 配置文件(资源文件):以properties作为拓展名的文件 Java代码是如何加载properties文件的? 必须使用Propert ...

  6. java读取配置文件属性

    在项目开发过程中,有时需要将其中用到的变量值在一个文件中统一管理,首先我选到了config.properties文件:下面这个代码是用于读取其中的变量值的类: package com.modem.te ...

  7. springBoot基础系列--properties配置

    原创作品,可以转载,但是请标注出处地址:http://www.cnblogs.com/V1haoge/p/7183408.html SpringBoot中免除了大部分手动配置,但是对于一些特定的情况, ...

  8. SpringBoot基础学习(二) SpringBoot全局配置文件及配置文件属性值注入

    全局配置文件 全局配置文件能够对一些默认配置值进行修改.SpringBoot 使用一个名为 application.properties 或者 application.yaml的文件作为全局配置文件, ...

  9. Android中使用java.util.Properties犯的错

    今天尝试使用java.util.Properties来保存应用配置,然而遇到了好几个问题,对于熟悉此内容的来说可能都是猪一样的错误,但难免有像我一样的新手再次遇到,希望此文能有所帮助. 错误1 jav ...

随机推荐

  1. 高并发场景下System.currentTimeMillis()的性能问题的优化 以及SnowFlakeIdWorker高性能ID生成器

    package xxx; import java.sql.Timestamp; import java.util.concurrent.*; import java.util.concurrent.a ...

  2. oracle下载地址

    12c 下载地址 http://www.oracle.com/technetwork/cn/database/enterprise-edition/downloads/index.html

  3. leetcode832

    vector<vector<int>> flipAndInvertImage(vector<vector<int>>& A) { vector& ...

  4. 【转载】C# 从服务器下载文件

    支持并尊重原创!原文地址:https://www.cnblogs.com/GoCircle/p/6429136.html 一.//TransmitFile实现下载 protected void But ...

  5. Python 小练习二 数据库MySQL、Redis

    import pymysql,redis def op_mysql(host,user,password,db,sql,port=3306,charset='utf8'): conn = pymysq ...

  6. HTML_基础篇v2

    网站图片页面显示案例 1.需求分析 需要在浏览器中显示2张图片信息,效果如下: 2.技术分析 [图片标签]<img /> 属性: src:指图片的位置(路径) 路径的写法:绝对路径和相对路 ...

  7. 在linux中获取错误返回信息&nbsp;&amp;…

    #include // void perror(const char *msg); #include // char *strerror(int errnum); #include //errno e ...

  8. mfs实际操作教程

    9. 实际操作案例 9.1 默认的垃圾回收时间是86400,存在一种可能性是垃圾还没回收完,你的存储容量就暴掉了.(案例提供者shinelian) 方案1:设置垃圾回收时间,积极监控存储容量.     ...

  9. Linux 安装lamp

    安装软件包编译器 gcc -v 查看是否存在 yum -y install gcc gcc-c++ mack rpm -q httpd 查看是否安装http rpm -e httpd --nodeps ...

  10. SpringBoot24 SpringDataJPA环境搭建、实体类注解、关联查询

    1 版本说明 JDK:1.8 MAVEN:3.5 SpringBoot:2.0.4 IDEA:旗舰版207.2 MySQL:5.5 2 SpringDataJPA环境搭建(SpringBoot版本) ...