Commit 351f8f05 authored by yanzg's avatar yanzg

异常处理显示

parent 1ea210d9
......@@ -26,20 +26,32 @@ public class DbPrintSql {
* @return 不带参数的SQL语句
*/
public String getStringSql(String sql, Object... paras) {
StringBuilder sb = new StringBuilder();
String[] split = sql.split("\\?");
int pos = 0;
// 进行SQL语句参数替换,后面增加一个空格,方便后续用正则表达式进行替换处理
for (Object item : paras) {
String str = StringHelper.toString(item);
if (str == null || item instanceof Number || item.getClass().isEnum() || item instanceof Boolean) {
if (str == null) {
sql = sql.replaceFirst("\\?", "null");
} else {
sql = sql.replaceFirst("\\?", str);
}
String strTo = str;
if (str == null) {
strTo = "null";
} else if (item instanceof Number || item.getClass().isEnum() || item instanceof Boolean) {
// 不进行处理
} else {
sql = sql.replaceFirst("\\?", "'" + str.replace("'", "''") + "'");
strTo = "'" + str.replace("'", "''") + "'";
}
sb.append(split[pos]);
pos++;
sb.append(strTo);
}
while (pos < split.length) {
sb.append(split[pos]);
pos++;
}
return sql;
return sb.toString();
}
/**
......
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