public class PlaceholderParser extends Object implements UnaryOperator<String>
一个简单的占位符解析器。给定占位符的左右边界符号以及转义符,
将允许把一段字符串中的占位符解析并替换为指定内容,支持指定转义符对边界符号进行转义。
比如:
String text = "select * from #[tableName] where id = #[id]";
PlaceholderParser parser = new PlaceholderParser(str -> "?", "#[", "]");
parser.apply(text); // = select * from ? where id = ?
Constructor and Description |
---|
PlaceholderParser(UnaryOperator<String> processor,
String prefix,
String suffix)
创建一个占位符解析器,默认转义符为
"\" |
PlaceholderParser(UnaryOperator<String> processor,
String prefix,
String suffix,
char escape)
创建一个占位符解析器
|
Modifier and Type | Method and Description |
---|---|
String |
apply(String text)
解析并替换字符串中的占位符
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
identity
public PlaceholderParser(UnaryOperator<String> processor, String prefix, String suffix)
"\"
processor
- 占位符处理器prefix
- 占位符开始符号,不允许为空suffix
- 占位符结束符号,不允许为空public PlaceholderParser(UnaryOperator<String> processor, String prefix, String suffix, char escape)
processor
- 占位符处理器prefix
- 占位符开始符号,不允许为空suffix
- 占位符结束符号,不允许为空escape
- 转义符Copyright © 2025. All rights reserved.