作者:Eddy 历史版本:1 最后编辑:龚清 更新时间:2024-11-20 15:41
适用版本:所有版本;
完整类名:com.lc.ibps.base.core.util.string.StringFormater
适用哪些服务?
- oauth服务
- platform服务
- business服务
- 通过business或skeleton创建的服务
方法介绍
format
- 格式化占位符
- 格式化带参数的字符串,如 /param/detail.ht?a=${0}&b=${1},注意字符串的参数从0下标开始,字符串的参数数量和args数组的数量要一致
- 方法定义
public static String format(String contentWithNumberPlaceHolder, Object... numberReplaceParams)
- 示例
String input = "/param/detail.ht?a=${0}&b=${1}";
String format = StringFormater.format(input, "a1", "b2");
formatStr
- 格式化占位符
- 格式化带参数的字符串,如 /param/detail.ht?a={0}&b={1},注意字符串的参数从0下标开始,字符串的参数数量和args数组的数量要一致
- 方法定义
public static String formatStr(String contentWithNumberPlaceHolder, Object... numberReplaceParams)
- 示例
String input = "/param/detail.ht?a={0}&b={1}";
String formatStr = StringFormater.formatStr(input, "a1", "b2");
formatByMap
- 格式化占位符
- 格式化带参数的字符串,如 /param/detail.ht?a=${a}&b=${b}
- 方法定义
public static String formatByMap(String contentWithNumberPlaceHolder, Map<String, String> keyReplaceParams)
- 示例
Map<String, String> keyReplaceParams = new HashMap<>();
keyReplaceParams.put("a","dada");
keyReplaceParams.put("b","dwww");
String input = "/param/detail.ht?a=${a}&b=${b}";
String formatByMap = StringFormater.formatByMap(input, keyReplaceParams);
replaceByMap
- 格式化占位符
- 格式化带参数的字符串,如 /param/detail.ht?a=${a}&b=${b}
- 方法定义
public static String replaceByMap(String contentWithBraces, Map<String, String> replaceParamMap)
- 示例
Map<String, String> keyReplaceParams = new HashMap<>();
keyReplaceParams.put("a","dada");
keyReplaceParams.put("b","dwww");
String input = "/param/detail.ht?a={a}&b={b}";
String replaceByMap = StringFormater.replaceByMap(input, keyReplaceParams);
replaceByMap
- 格式化占位符
- 格式化带参数的字符串,如 /param/detail.ht?a=${a}&b=${b}
- 方法定义
public static String replaceByMap(String contentWithBraces, Map<String, String> replaceParamMap,String regularCompare)
- 示例
Map<String, String> keyReplaceParams = new HashMap<>();
keyReplaceParams.put("a","dada");
keyReplaceParams.put("b","dwww");
String input = "/param/detail.ht?a={a}&b={b}";
String replaceByMap = StringFormater.replaceByMap(input, keyReplaceParams, "\\{(.*?)\\}");
transferKeyAndToReplace
- 解析占位符
- 如:select * from {{pageSqlEnd}}
- 方法定义
public static Map<String, String> transferKeyAndToReplace(String contentWithBraces, String regularCompare)
- 示例
String sql = "select * from {{pageSqlEnd}}";
String PAGE_SQL_START_KEY_REG = "\\{\\{(pageSqlEnd)\\}\\}";
// 删除分页子句占位符
Map<String, String> allMap = StringFormater.transferKeyAndToReplace(sql, PAGE_SQL_END_KEY_REG);
if (BeanUtils.isNotEmpty(allMap)) {
Map<String, String> valueMap = new HashMap<>();
valueMap.put(PAGE_SQL_START_KEY, "");
valueMap.put(PAGE_SQL_END_KEY, "");
sql = StringFormater.replaceByMap(sql, valueMap, PAGE_SQL_START_KEY_REG);
sql = StringFormater.replaceByMap(sql, valueMap, PAGE_SQL_END_KEY_REG);
}