public class StringTemplate extends Object
Improve the readability of string concat and avoid the awkwardness of having the replaced string in the replace value.
StringTemplate.fix("access_token=ACCESS_TOKEN&openid=OPENID&lang=en")
.bindStr("ACCESS_TOKEN", token)
.bindStr("OPENID", openid)
.toString();
The efficiency and effect equal to
"access_token="+token+"&openid="+openid+"&lang=en"
and faster than String.format, replace, and other dynamic replace.
Note that
(1) bindStr and bindReg will be overwritten if they are the same string.
(2) must end with toString() to avoid ThreadLocal leakage.
| Modifier and Type | Class and Description |
|---|---|
static class |
StringTemplate.B |
| Constructor and Description |
|---|
StringTemplate() |
| Modifier and Type | Method and Description |
|---|---|
static @NotNull StringTemplate.B |
dyn(@NotNull String str)
Dynamic string, first compile bindKey, then merge it with bindObj.
|
static @NotNull StringTemplate.B |
fix(@NotNull String str)
Static fixed strings, replace first and cache for later.
|
static @NotNull StringTemplate.B |
one(@NotNull String str)
Construct one-time strings without caching compiling results
|
@NotNull public static @NotNull StringTemplate.B fix(@NotNull @NotNull String str)
@NotNull public static @NotNull StringTemplate.B dyn(@NotNull @NotNull String str)
@NotNull public static @NotNull StringTemplate.B one(@NotNull @NotNull String str)
Copyright © 2023. All rights reserved.