public final class Props extends Properties implements BasicTypeGetter<String>, OptBasicTypeGetter<String>
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
EXT_NAME
默认配置文件扩展名
|
defaults| 构造器和说明 |
|---|
Props()
构造
|
Props(File propertiesFile)
构造
|
Props(File propertiesFile,
Charset charset)
构造
|
Props(File propertiesFile,
String charsetName)
构造
|
Props(Properties properties)
构造,使用URL读取
|
Props(String path)
构造,使用相对于Class文件根目录的相对路径
|
Props(String path,
Charset charset)
构造,使用相对于Class文件根目录的相对路径
|
Props(String path,
Class<?> clazz)
构造,相对于classes读取文件
|
Props(String path,
Class<?> clazz,
Charset charset)
构造,相对于classes读取文件
|
Props(String path,
Class<?> clazz,
String charsetName)
构造,相对于classes读取文件
|
Props(String path,
String charsetName)
构造,使用相对于Class文件根目录的相对路径
|
Props(URL propertiesUrl)
构造,使用URL读取
|
Props(URL propertiesUrl,
Charset charset)
构造,使用URL读取
|
Props(URL propertiesUrl,
String charsetName)
构造,使用URL读取
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
autoLoad(boolean autoReload)
在配置文件变更时自动加载
|
static Props |
create()
构建一个空的Props,用于手动加入参数
|
<T> T |
fillBean(T bean,
String prefix)
将配置文件转换为Bean,支持嵌套Bean
支持的表达式: persion persion.name persons[3] person.friends[5].name ['person']['friends'][5]['name'] |
String |
getAndRemoveStr(String... keys)
获取并删除键值对,当指定键对应值非空时,返回并删除这个值,后边的键对应的值不再查找
|
BigDecimal |
getBigDecimal(String key) |
BigDecimal |
getBigDecimal(String key,
BigDecimal defaultValue) |
BigInteger |
getBigInteger(String key) |
BigInteger |
getBigInteger(String key,
BigInteger defaultValue) |
Boolean |
getBool(String key) |
Boolean |
getBool(String key,
Boolean defaultValue) |
Byte |
getByte(String key) |
Byte |
getByte(String key,
Byte defaultValue) |
Character |
getChar(String key) |
Character |
getChar(String key,
Character defaultValue) |
Date |
getDate(String key) |
Date |
getDate(String key,
Date defaultValue) |
Double |
getDouble(String key) |
Double |
getDouble(String key,
Double defaultValue) |
<E extends Enum<E>> |
getEnum(Class<E> clazz,
String key) |
<E extends Enum<E>> |
getEnum(Class<E> clazz,
String key,
E defaultValue) |
Float |
getFloat(String key) |
Float |
getFloat(String key,
Float defaultValue) |
Integer |
getInt(String key) |
Integer |
getInt(String key,
Integer defaultValue) |
Long |
getLong(String key) |
Long |
getLong(String key,
Long defaultValue) |
Object |
getObj(String key) |
Object |
getObj(String key,
Object defaultValue) |
static Props |
getProp(String resource)
获得Classpath下的Properties文件
|
static Props |
getProp(String resource,
Charset charset)
获得Classpath下的Properties文件
|
static Props |
getProp(String resource,
String charsetName)
获得Classpath下的Properties文件
|
Short |
getShort(String key) |
Short |
getShort(String key,
Short defaultValue) |
String |
getStr(String key) |
String |
getStr(String key,
String defaultValue) |
void |
load()
重新加载配置文件
|
void |
load(Resource resource)
初始化配置文件
|
void |
load(URL url)
初始化配置文件
|
void |
setProperty(String key,
Object value)
设置值,无给定键创建之。
|
void |
store(String absolutePath)
持久化当前设置,会覆盖掉之前的设置
|
void |
store(String path,
Class<?> clazz)
存储当前设置,会覆盖掉以前的设置
|
<T> T |
toBean(Class<T> beanClass)
将配置文件转换为Bean,支持嵌套Bean
支持的表达式: persion persion.name persons[3] person.friends[5].name ['person']['friends'][5]['name'] |
<T> T |
toBean(Class<T> beanClass,
String prefix)
将配置文件转换为Bean,支持嵌套Bean
支持的表达式: persion persion.name persons[3] person.friends[5].name ['person']['friends'][5]['name'] |
Properties |
toProperties()
转换为标准的
Properties对象 |
getProperty, getProperty, list, list, load, load, loadFromXML, propertyNames, save, setProperty, store, store, storeToXML, storeToXML, stringPropertyNamesclear, clone, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keys, keySet, merge, put, putAll, putIfAbsent, rehash, remove, remove, replace, replace, replaceAll, size, toString, valuespublic Props()
public Props(String path)
path - 配置文件路径,相对于ClassPath,或者使用绝对路径public Props(String path, String charsetName)
path - 相对或绝对路径charsetName - 字符集public Props(String path, Charset charset)
path - 相对或绝对路径charset - 字符集public Props(File propertiesFile)
propertiesFile - 配置文件对象public Props(File propertiesFile, String charsetName)
propertiesFile - 配置文件对象charsetName - 字符集public Props(File propertiesFile, Charset charset)
propertiesFile - 配置文件对象charset - 字符集public Props(String path, Class<?> clazz, String charsetName)
path - 相对路径clazz - 基准类charsetName - 字符集public Props(String path, Class<?> clazz, Charset charset)
path - 相对路径clazz - 基准类charset - 字符集public Props(URL propertiesUrl)
propertiesUrl - 属性文件路径public Props(URL propertiesUrl, String charsetName)
propertiesUrl - 属性文件路径charsetName - 字符集public Props(URL propertiesUrl, Charset charset)
propertiesUrl - 属性文件路径charset - 字符集public Props(Properties properties)
properties - 属性文件路径public static Props create()
public static Props getProp(String resource)
resource - 资源(相对Classpath的路径)public static Props getProp(String resource, String charsetName)
resource - 资源(相对Classpath的路径)charsetName - 字符集public static Props getProp(String resource, Charset charset)
resource - 资源(相对Classpath的路径)charset - 字符集public void load()
public void autoLoad(boolean autoReload)
autoReload - 是否自动加载public Object getObj(String key, Object defaultValue)
getObj 在接口中 OptBasicTypeGetter<String>public Object getObj(String key)
getObj 在接口中 BasicTypeGetter<String>public String getStr(String key, String defaultValue)
getStr 在接口中 OptBasicTypeGetter<String>public String getStr(String key)
getStr 在接口中 BasicTypeGetter<String>public Integer getInt(String key, Integer defaultValue)
getInt 在接口中 OptBasicTypeGetter<String>public Integer getInt(String key)
getInt 在接口中 BasicTypeGetter<String>public Boolean getBool(String key, Boolean defaultValue)
getBool 在接口中 OptBasicTypeGetter<String>public Boolean getBool(String key)
getBool 在接口中 BasicTypeGetter<String>public Long getLong(String key, Long defaultValue)
getLong 在接口中 OptBasicTypeGetter<String>public Long getLong(String key)
getLong 在接口中 BasicTypeGetter<String>public Character getChar(String key, Character defaultValue)
getChar 在接口中 OptBasicTypeGetter<String>public Character getChar(String key)
getChar 在接口中 BasicTypeGetter<String>public Float getFloat(String key)
getFloat 在接口中 BasicTypeGetter<String>public Float getFloat(String key, Float defaultValue)
getFloat 在接口中 OptBasicTypeGetter<String>public Double getDouble(String key, Double defaultValue) throws NumberFormatException
getDouble 在接口中 OptBasicTypeGetter<String>NumberFormatExceptionpublic Double getDouble(String key) throws NumberFormatException
getDouble 在接口中 BasicTypeGetter<String>NumberFormatExceptionpublic Short getShort(String key, Short defaultValue)
getShort 在接口中 OptBasicTypeGetter<String>public Short getShort(String key)
getShort 在接口中 BasicTypeGetter<String>public Byte getByte(String key, Byte defaultValue)
getByte 在接口中 OptBasicTypeGetter<String>public Byte getByte(String key)
getByte 在接口中 BasicTypeGetter<String>public BigDecimal getBigDecimal(String key, BigDecimal defaultValue)
getBigDecimal 在接口中 OptBasicTypeGetter<String>public BigDecimal getBigDecimal(String key)
getBigDecimal 在接口中 BasicTypeGetter<String>public BigInteger getBigInteger(String key, BigInteger defaultValue)
getBigInteger 在接口中 OptBasicTypeGetter<String>public BigInteger getBigInteger(String key)
getBigInteger 在接口中 BasicTypeGetter<String>public <E extends Enum<E>> E getEnum(Class<E> clazz, String key, E defaultValue)
getEnum 在接口中 OptBasicTypeGetter<String>public <E extends Enum<E>> E getEnum(Class<E> clazz, String key)
getEnum 在接口中 BasicTypeGetter<String>public Date getDate(String key, Date defaultValue)
getDate 在接口中 OptBasicTypeGetter<String>public Date getDate(String key)
getDate 在接口中 BasicTypeGetter<String>public String getAndRemoveStr(String... keys)
keys - 键列表,常用于别名public Properties toProperties()
Properties对象Properties对象public <T> T toBean(Class<T> beanClass)
persion persion.name persons[3] person.friends[5].name ['person']['friends'][5]['name']
T - Bean类型beanClass - Bean类public <T> T toBean(Class<T> beanClass, String prefix)
persion persion.name persons[3] person.friends[5].name ['person']['friends'][5]['name']
T - Bean类型beanClass - Bean类prefix - 公共前缀,不指定前缀传null,当指定前缀后非此前缀的属性被忽略public <T> T fillBean(T bean,
String prefix)
persion persion.name persons[3] person.friends[5].name ['person']['friends'][5]['name']
T - Bean类型bean - Bean对象prefix - 公共前缀,不指定前缀传null,当指定前缀后非此前缀的属性被忽略public void setProperty(String key, Object value)
key - 属性键value - 属性值public void store(String absolutePath) throws IORuntimeException
absolutePath - 设置文件的绝对路径IORuntimeException - IO异常,可能为文件未找到Copyright © 2021. All rights reserved.