public class PlaceholderUtil extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
DEFAULT_PLACEHOLDER_PREFIX
默认前缀占位符
|
static String |
DEFAULT_PLACEHOLDER_SUFFIX
默认后缀占位符
|
private static PlaceholderUtil |
DEFAULT_RESOLVER
默认单例解析器
|
private String |
placeholderPrefix
占位符前缀
|
private String |
placeholderSuffix
占位符后缀
|
| 限定符 | 构造器和说明 |
|---|---|
private |
PlaceholderUtil() |
private |
PlaceholderUtil(String placeholderPrefix,
String placeholderSuffix) |
| 限定符和类型 | 方法和说明 |
|---|---|
static PlaceholderUtil |
getDefaultResolver()
获取默认的占位符解析器,即占位符前缀为"${", 后缀为"}"
|
static PlaceholderUtil |
getResolver(String placeholderPrefix,
String placeholderSuffix) |
String |
resolve(String content,
Object[] values)
解析带有指定占位符的模板字符串,默认占位符为前缀:${ 后缀:}
|
String |
resolve(String content,
String... values)
解析带有指定占位符的模板字符串,默认占位符为前缀:${ 后缀:}
|
String |
resolveByMap(String content,
Map<String,Object> valueMap)
替换模板中占位符内容,占位符的内容即为map key对应的值,key为占位符中的内容
|
String |
resolveByProperties(String content,
Properties properties)
根据properties文件替换占位符内容
|
String |
resolveByRule(String content,
java.util.function.Function<String,String> rule)
根据替换规则来替换指定模板中的占位符值
|
public static final String DEFAULT_PLACEHOLDER_PREFIX
public static final String DEFAULT_PLACEHOLDER_SUFFIX
private static final PlaceholderUtil DEFAULT_RESOLVER
private String placeholderPrefix
private String placeholderSuffix
public static PlaceholderUtil getDefaultResolver()
public static PlaceholderUtil getResolver(String placeholderPrefix, String placeholderSuffix)
public String resolve(String content, String... values)
content - 要解析的带有占位符的模板字符串values - 按照模板占位符索引位置设置对应的值public String resolve(String content, Object[] values)
content - 要解析的带有占位符的模板字符串values - 按照模板占位符索引位置设置对应的值public String resolveByRule(String content, java.util.function.Function<String,String> rule)
content - 要解析的字符串rule - 解析规则回调public String resolveByMap(String content, Map<String,Object> valueMap)
content - 模板内容valueMap - 值映射public String resolveByProperties(String content, Properties properties)
content - 模板内容properties - 配置Copyright © 2024. All rights reserved.