Commit b96db6b2 authored by yanzg's avatar yanzg

修改实例化关系

parent c1063d50
......@@ -27,11 +27,15 @@ public class DbPrintSql {
public String getStringSql(String sql, Object... paras) {
StringBuilder sb = new StringBuilder();
// 进行SQL语句参数替换,后面增加一个空格,方便后续用正则表达式进行替换处理
String[] split = sql.split("\\?");
int pos = 0;
// 进行SQL语句参数替换,后面增加一个空格,方便后续用正则表达式进行替换处理
for (Object item : paras) {
while (pos < split.length) {
sb.append(split[pos]);
if (pos == split.length - 1) {
break;
}
Object item = paras.length > pos ? paras[pos] : null;
String str = StringHelper.toString(item);
String strTo = str;
if (str == null) {
......@@ -41,15 +45,11 @@ public class DbPrintSql {
} else {
strTo = "'" + str.replace("'", "''") + "'";
}
sb.append(split[pos]);
pos++;
sb.append(strTo);
}
while (pos < split.length) {
sb.append(split[pos]);
pos++;
}
return sb.toString();
}
......
import com.yanzuoguang.db.impl.DbPrintSql;
import org.junit.Test;
public class TestDbPrintSql {
@Test
public void test(){
DbPrintSql printSql = new DbPrintSql();
String stringSql = printSql.getStringSql("select * from where id = ? AND name = ? and removeFlag = 0 ", "1");
System.out.println(stringSql);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment