作者:Eddy  历史版本:1  最后编辑:龚清  更新时间:2024-09-20 15:13

适用版本:所有版本;
完整类名:com.lc.ibps.base.core.util.string.StringFormater

适用哪些服务?

  1. oauth服务
  2. platform服务
  3. business服务
  4. 通过business或skeleton创建的服务

方法介绍

format

  1. 格式化占位符
  2. 格式化带参数的字符串,如 /param/detail.ht?a=${0}&b=${1},注意字符串的参数从0下标开始,字符串的参数数量和args数组的数量要一致
  3. 方法定义public static String format(String contentWithNumberPlaceHolder, Object... numberReplaceParams)
  4. 示例
String input = "/param/detail.ht?a=${0}&b=${1}";
String format = StringFormater.format(input, "a1", "b2");

formatStr

  1. 格式化占位符
  2. 格式化带参数的字符串,如 /param/detail.ht?a={0}&b={1},注意字符串的参数从0下标开始,字符串的参数数量和args数组的数量要一致
  3. 方法定义public static String formatStr(String contentWithNumberPlaceHolder, Object... numberReplaceParams)
  4. 示例
String input = "/param/detail.ht?a={0}&b={1}";
String formatStr = StringFormater.formatStr(input, "a1", "b2");

formatByMap

  1. 格式化占位符
  2. 格式化带参数的字符串,如 /param/detail.ht?a=${a}&b=${b}
  3. 方法定义public static String formatByMap(String contentWithNumberPlaceHolder, Map<String, String> keyReplaceParams)
  4. 示例
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

  1. 格式化占位符
  2. 格式化带参数的字符串,如 /param/detail.ht?a=${a}&b=${b}
  3. 方法定义public static String replaceByMap(String contentWithBraces, Map<String, String> replaceParamMap)
  4. 示例
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

  1. 格式化占位符
  2. 格式化带参数的字符串,如 /param/detail.ht?a=${a}&b=${b}
  3. 方法定义public static String replaceByMap(String contentWithBraces, Map<String, String> replaceParamMap,String regularCompare)
  4. 示例
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

  1. 解析占位符
  2. 如:select * from {{pageSqlEnd}}
  3. 方法定义public static Map<String, String> transferKeyAndToReplace(String contentWithBraces, String regularCompare)
  4. 示例
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);
}