mirror of
https://github.com/chillzhuang/blade-tool
synced 2025-04-20 19:49:20 +08:00
⚡ 优化TemplateUtil
This commit is contained in:
parent
945efc8fbf
commit
cd71fcbcda
@ -53,4 +53,25 @@ public class TemplateUtil {
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析模版
|
||||||
|
*
|
||||||
|
* @param template 模版
|
||||||
|
* @param params 参数
|
||||||
|
* @return 解析后的字符串
|
||||||
|
*/
|
||||||
|
public static String safeProcess(String template, Kv params) {
|
||||||
|
Matcher matcher = pattern.matcher(template);
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
while (matcher.find()) {
|
||||||
|
String key = matcher.group(1) != null ? matcher.group(1) : matcher.group(2);
|
||||||
|
String replacement = params.getStr(key);
|
||||||
|
if (replacement != null) {
|
||||||
|
matcher.appendReplacement(sb, replacement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
matcher.appendTail(sb);
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user