mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
!1122 SpringUtil增加getProperty重载
Merge pull request !1122 from Charles7c/v5-dev
This commit is contained in:
commit
3c68b2b7b1
@ -182,10 +182,35 @@ public class SpringUtil implements BeanFactoryPostProcessor, ApplicationContextA
|
|||||||
* @since 5.3.3
|
* @since 5.3.3
|
||||||
*/
|
*/
|
||||||
public static String getProperty(String key) {
|
public static String getProperty(String key) {
|
||||||
|
return getProperty(key, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取配置文件配置项的值
|
||||||
|
*
|
||||||
|
* @param key 配置项key
|
||||||
|
* @param defaultValue 默认值
|
||||||
|
* @return 属性值
|
||||||
|
* @since 5.8.24
|
||||||
|
*/
|
||||||
|
public static String getProperty(String key, String defaultValue) {
|
||||||
|
return getProperty(key, String.class, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取配置文件配置项的值
|
||||||
|
*
|
||||||
|
* @param key 配置项key
|
||||||
|
* @param targetType 配置项类型
|
||||||
|
* @param defaultValue 默认值
|
||||||
|
* @return 属性值
|
||||||
|
* @since 5.8.24
|
||||||
|
*/
|
||||||
|
public static <T> T getProperty(String key, Class<T> targetType, T defaultValue) {
|
||||||
if (null == applicationContext) {
|
if (null == applicationContext) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return applicationContext.getEnvironment().getProperty(key);
|
return applicationContext.getEnvironment().getProperty(key, targetType, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user