Class Props
- All Implemented Interfaces:
Serializable, Cloneable, Map<Object,Object>
Properties 配置增强,参考 Hutool 的
Props 设计。
支持从 classpath 相对路径或文件加载 .properties,提供类型安全的读取(带默认值)、
转换为 Bean 与 Map 快照。
- Since:
- 1.9.0
- Author:
- suretool
- See Also:
-
Nested Class Summary
-
Field Summary
Fields inherited from class Properties
defaults -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetBigDecimal(String key, BigDecimal defaultValue) 读取 BigDecimal,不存在或解析失败返回默认值。boolean读取 boolean,不存在返回默认值。double读取 double,不存在或解析失败返回默认值。int读取 int,不存在或解析失败返回默认值。long读取 long,不存在或解析失败返回默认值。读取原始对象(字符串值)。读取字符串,不存在返回null。读取字符串,不存在或为空返回默认值。从文件加载(UTF-8)。voidload(InputStream in) 以 UTF-8 覆盖重载:Properties.load(InputStream)默认 ISO-8859-1。从 classpath 相对路径加载(UTF-8)。<T> T转 Bean:属性名 → Bean 属性(带类型转换)。toMap()转为 Map 快照(键值均为字符串)。Methods inherited from class Properties
clear, clone, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, get, getOrDefault, getProperty, getProperty, hashCode, isEmpty, keys, keySet, list, list, load, loadFromXML, merge, propertyNames, put, putAll, putIfAbsent, rehash, remove, remove, replace, replace, replaceAll, save, setProperty, size, store, store, storeToXML, storeToXML, storeToXML, stringPropertyNames, toString, values
-
Constructor Details
-
Props
public Props()空配置。 -
Props
从 classpath 相对路径加载。- Parameters:
path- classpath 相对路径(如"config/app.properties")- Throws:
IllegalArgumentException- 资源不存在或加载失败
-
Props
-
-
Method Details
-
load
从 classpath 相对路径加载(UTF-8)。- Parameters:
path- classpath 相对路径- Returns:
- 本对象
- Throws:
IllegalArgumentException- 资源不存在或加载失败
-
load
从文件加载(UTF-8)。- Parameters:
file- 文件- Returns:
- 本对象
- Throws:
IllegalArgumentException- 文件不存在或加载失败
-
getStr
-
getStr
-
getInt
读取 int,不存在或解析失败返回默认值。- Parameters:
key- 键defaultValue- 默认值- Returns:
- 值或默认值
-
getLong
读取 long,不存在或解析失败返回默认值。- Parameters:
key- 键defaultValue- 默认值- Returns:
- 值或默认值
-
getDouble
读取 double,不存在或解析失败返回默认值。- Parameters:
key- 键defaultValue- 默认值- Returns:
- 值或默认值
-
getBool
读取 boolean,不存在返回默认值。- Parameters:
key- 键defaultValue- 默认值- Returns:
- 值或默认值
-
getBigDecimal
读取 BigDecimal,不存在或解析失败返回默认值。- Parameters:
key- 键defaultValue- 默认值- Returns:
- 值或默认值
-
getObj
-
toBean
转 Bean:属性名 → Bean 属性(带类型转换)。- Type Parameters:
T- Bean 类型- Parameters:
beanClass- Bean 类- Returns:
- Bean 实例
-
toMap
-
load
以 UTF-8 覆盖重载:Properties.load(InputStream)默认 ISO-8859-1。- Overrides:
loadin classProperties- Parameters:
in- 输入流- Throws:
IOException- IO 异常
-