public final class Props extends Properties implements BasicTypeGetter<String>, OptBasicTypeGetter<String>
Modifier and Type | Field and Description |
---|---|
static String |
EXT_NAME
默认配置文件扩展名
|
defaults
Constructor and Description |
---|
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读取
|
Modifier and Type | Method and Description |
---|---|
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型属性值
|
BigDecimal |
getBigDecimal(String key,
BigDecimal defaultValue)
获取BigDecimal型属性值
若获得的值为不可见字符,使用默认值 |
BigInteger |
getBigInteger(String key)
获取BigInteger型属性值
|
BigInteger |
getBigInteger(String key,
BigInteger defaultValue)
获取BigInteger型属性值
若获得的值为不可见字符,使用默认值 |
Boolean |
getBool(String key)
获取boolean型属性值
|
Boolean |
getBool(String key,
Boolean defaultValue)
获取boolean型属性值
若获得的值为不可见字符,使用默认值 |
Byte |
getByte(String key)
获取byte型属性值
|
Byte |
getByte(String key,
Byte defaultValue)
获取byte型属性值
若获得的值为不可见字符,使用默认值 |
Character |
getChar(String key)
获取char型属性值
|
Character |
getChar(String key,
Character defaultValue)
获取char型属性值
若获得的值为不可见字符,使用默认值 |
Date |
getDate(String key)
获取Date类型值
|
Date |
getDate(String key,
Date defaultValue)
获取Date类型值
|
Double |
getDouble(String key)
获取double型属性值
|
Double |
getDouble(String key,
Double defaultValue)
获取double型属性值
若获得的值为不可见字符,使用默认值 |
<E extends Enum<E>> |
getEnum(Class<E> clazz,
String key)
获得Enum类型的值
|
<E extends Enum<E>> |
getEnum(Class<E> clazz,
String key,
E defaultValue)
获得Enum类型的值
|
Float |
getFloat(String key)
获取float型属性值
|
Float |
getFloat(String key,
Float defaultValue)
获取float型属性值
若获得的值为不可见字符,使用默认值 |
Integer |
getInt(String key)
获取int型属性值
|
Integer |
getInt(String key,
Integer defaultValue)
获取int型属性值
若获得的值为不可见字符,使用默认值 |
Long |
getLong(String key)
获取long型属性值
|
Long |
getLong(String key,
Long defaultValue)
获取Long型属性值
若获得的值为不可见字符,使用默认值 |
Object |
getObj(String key)
获取Object属性值
|
Object |
getObj(String key,
Object defaultValue)
获取Object属性值
|
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型属性值
|
Short |
getShort(String key,
Short defaultValue)
获取short型属性值
若获得的值为不可见字符,使用默认值 |
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, stringPropertyNames
clear, 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, values
public static final String EXT_NAME
public 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)
path
- 相对路径clazz
- 基准类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)
OptBasicTypeGetter
getObj
in interface OptBasicTypeGetter<String>
key
- 属性名defaultValue
- 默认值public Object getObj(String key)
BasicTypeGetter
getObj
in interface BasicTypeGetter<String>
key
- 属性名public String getStr(String key, String defaultValue)
OptBasicTypeGetter
getStr
in interface OptBasicTypeGetter<String>
key
- 属性名defaultValue
- 默认值public String getStr(String key)
BasicTypeGetter
getStr
in interface BasicTypeGetter<String>
key
- 属性名public Integer getInt(String key, Integer defaultValue)
OptBasicTypeGetter
getInt
in interface OptBasicTypeGetter<String>
key
- 属性名defaultValue
- 默认值public Integer getInt(String key)
BasicTypeGetter
getInt
in interface BasicTypeGetter<String>
key
- 属性名public Boolean getBool(String key, Boolean defaultValue)
OptBasicTypeGetter
getBool
in interface OptBasicTypeGetter<String>
key
- 属性名defaultValue
- 默认值public Boolean getBool(String key)
BasicTypeGetter
getBool
in interface BasicTypeGetter<String>
key
- 属性名public Long getLong(String key, Long defaultValue)
OptBasicTypeGetter
getLong
in interface OptBasicTypeGetter<String>
key
- 属性名defaultValue
- 默认值public Long getLong(String key)
BasicTypeGetter
getLong
in interface BasicTypeGetter<String>
key
- 属性名public Character getChar(String key, Character defaultValue)
OptBasicTypeGetter
getChar
in interface OptBasicTypeGetter<String>
key
- 属性名defaultValue
- 默认值public Character getChar(String key)
BasicTypeGetter
getChar
in interface BasicTypeGetter<String>
key
- 属性名public Float getFloat(String key)
BasicTypeGetter
getFloat
in interface BasicTypeGetter<String>
key
- 属性名public Float getFloat(String key, Float defaultValue)
OptBasicTypeGetter
getFloat
in interface OptBasicTypeGetter<String>
key
- 属性名defaultValue
- 默认值public Double getDouble(String key, Double defaultValue) throws NumberFormatException
OptBasicTypeGetter
getDouble
in interface OptBasicTypeGetter<String>
key
- 属性名defaultValue
- 默认值NumberFormatException
public Double getDouble(String key) throws NumberFormatException
BasicTypeGetter
getDouble
in interface BasicTypeGetter<String>
key
- 属性名NumberFormatException
public Short getShort(String key, Short defaultValue)
OptBasicTypeGetter
getShort
in interface OptBasicTypeGetter<String>
key
- 属性名defaultValue
- 默认值public Short getShort(String key)
BasicTypeGetter
getShort
in interface BasicTypeGetter<String>
key
- 属性名public Byte getByte(String key, Byte defaultValue)
OptBasicTypeGetter
getByte
in interface OptBasicTypeGetter<String>
key
- 属性名defaultValue
- 默认值public Byte getByte(String key)
BasicTypeGetter
getByte
in interface BasicTypeGetter<String>
key
- 属性名public BigDecimal getBigDecimal(String key, BigDecimal defaultValue)
OptBasicTypeGetter
getBigDecimal
in interface OptBasicTypeGetter<String>
key
- 属性名defaultValue
- 默认值public BigDecimal getBigDecimal(String key)
BasicTypeGetter
getBigDecimal
in interface BasicTypeGetter<String>
key
- 属性名public BigInteger getBigInteger(String key, BigInteger defaultValue)
OptBasicTypeGetter
getBigInteger
in interface OptBasicTypeGetter<String>
key
- 属性名defaultValue
- 默认值public BigInteger getBigInteger(String key)
BasicTypeGetter
getBigInteger
in interface BasicTypeGetter<String>
key
- 属性名public <E extends Enum<E>> E getEnum(Class<E> clazz, String key, E defaultValue)
OptBasicTypeGetter
getEnum
in interface OptBasicTypeGetter<String>
E
- 枚举类型clazz
- Enum的Classkey
- KEYdefaultValue
- 默认值public <E extends Enum<E>> E getEnum(Class<E> clazz, String key)
BasicTypeGetter
getEnum
in interface BasicTypeGetter<String>
E
- 枚举类型clazz
- Enum的Classkey
- KEYpublic Date getDate(String key, Date defaultValue)
OptBasicTypeGetter
getDate
in interface OptBasicTypeGetter<String>
key
- 属性名defaultValue
- 默认值public Date getDate(String key)
BasicTypeGetter
getDate
in interface BasicTypeGetter<String>
key
- 属性名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 © 2024. All rights reserved.