String中文字替换<递归算法> private static String resSql = ""; /** * @param 替换sql 语句中以startWith开头, 以endWith结尾的String 并且得到中间的String * @sql 进行替换的String * @startWith 以XX开头 * @endWith 以XX结尾 * @replaceWith 替换成文字 * */ private static String replaceParams(String sql, String startWith, String endWith, String replaceWith) { resSql = sql; List<String> paramList = new ArrayList<String>(); if (sql.indexOf(startWith, 0) > 0) { int startNUm = resSql.indexOf(startWith, 0); int endNum = resSql.indexOf(endWith, startNUm); String paramName = resSql.substring(startNUm, endNum); paramName = paramName.substring(1, paramName.length()); paramList.add(paramName); resSql = resSql.replace(startWith + paramName + endWith, replaceWith); } else resSql = ""; if (resSql.indexOf(startWith) > 0) replaceParams(resSql, "{", "}", "?"); return resSql; } |
|
来自: Sunny_Gql > 《Java Tools》