添加方法 getPropertyToArray

This commit is contained in:
thinkgem
2023-04-10 09:48:07 +08:00
parent 30acc93b3c
commit 42ee036804
3 changed files with 25 additions and 20 deletions

View File

@@ -4,6 +4,16 @@
*/
package com.jeesite.common.io;
import com.jeesite.common.codec.EncodeUtils;
import com.jeesite.common.collect.SetUtils;
import com.jeesite.common.lang.ObjectUtils;
import com.jeesite.common.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.core.env.Environment;
import org.springframework.core.io.Resource;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
@@ -13,17 +23,6 @@ import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.core.env.Environment;
import org.springframework.core.io.Resource;
import com.jeesite.common.codec.EncodeUtils;
import com.jeesite.common.collect.SetUtils;
import com.jeesite.common.lang.ObjectUtils;
import com.jeesite.common.lang.StringUtils;
/**
* Properties工具类 可载入多个properties、yml文件
* 相同的属性在最后载入的文件中的值将会覆盖之前的值,
@@ -207,6 +206,15 @@ public class PropertiesUtils {
return value != null ? value : defaultValue;
}
/**
* 获取配置文件中String类型的值取不到从System.getProperty获取取不到返回空。
* 对属性值进行 “,“ 逗号进行 split 分割,并返回
* @return 获取不到返回空defValue默认值
*/
public String[] getPropertyToArray(String key, String defValue) {
return StringUtils.split(getProperty(key, defValue), ",");
}
/**
* 获取配置文件中Boolean类型的值取不到从System.getProperty获取取不到返回空。
* @return 获取不到返回空defValue默认值如果结果为非布尔类型则返回false