PropertiesUtils 增加 getPropertyToBoolean、getPropertyToInteger 方法

This commit is contained in:
thinkgem
2021-05-15 21:23:05 +08:00
parent 2ea39dd4d8
commit af1c45601c

View File

@@ -198,12 +198,28 @@ public class PropertiesUtils {
}
/**
* 取出String类型的Property但以System的Property优先如果都为null则返回defaultValue值
* 获取配置文件中String类型的但以System的Property优先如果都为null则返回defaultValue值
*/
public String getProperty(String key, String defaultValue) {
String value = getProperty(key);
return value != null ? value : defaultValue;
}
/**
* 获取配置文件中Boolean类型的值取不到从System.getProperty获取取不到返回空。
* @return 获取不到返回空defValue默认值
*/
public Boolean getPropertyToBoolean(String key, String defValue) {
return ObjectUtils.toBoolean(getProperty(key, defValue));
}
/**
* 获取配置文件中Integer类型的值取不到从System.getProperty获取取不到返回空。
* @return 获取不到返回空defValue默认值
*/
public Integer getPropertyToInteger(String key, String defValue) {
return ObjectUtils.toInteger(getProperty(key, defValue));
}
/**
* 设置环境属性