소스 검색

修改mybatis拦截器实现,增加容错性代码

Signed-off-by: luoshi <luoshi@qmth.com.cn>
luoshi 11 달 전
부모
커밋
dfc9ff79e0
1개의 변경된 파일10개의 추가작업 그리고 5개의 파일을 삭제
  1. 10 5
      data-mybatis-plus/src/main/java/com/qmth/boot/mybatis/plugin/MybatisProfilerPlugin.java

+ 10 - 5
data-mybatis-plus/src/main/java/com/qmth/boot/mybatis/plugin/MybatisProfilerPlugin.java

@@ -45,8 +45,12 @@ public class MybatisProfilerPlugin implements Interceptor {
         Object result = invocation.proceed();
         long cost = System.currentTimeMillis() - start;
         if (profilerProperties.isEnable() && cost > profilerProperties.getThreshold().toMillis()) {
-            String sql = generateSql(invocation);
-            log.info("Sql time cost: " + cost + "ms\n" + sql);
+            try {
+                String sql = generateSql(invocation);
+                log.info("Sql time cost: " + cost + "ms\n" + sql);
+            } catch (Exception e) {
+                log.error("Sql profiler error", e);
+            }
         }
         return result;
     }
@@ -91,10 +95,11 @@ public class MybatisProfilerPlugin implements Interceptor {
                     } else if (boundSql.hasAdditionalParameter(propertyName)) {
                         Object obj = boundSql.getAdditionalParameter(propertyName);
                         sql = sql.replaceFirst("\\?", Matcher.quoteReplacement(getParameterValue(obj)));
-                    } else {
-                        // 如果都没有,说明SQL匹配不上,带上“缺失”方便找问题
-                        sql = sql.replaceFirst("\\?", "缺失");
                     }
+                    //else {
+                    // 如果都没有,说明SQL匹配不上,带上“缺失”方便找问题
+                    // sql = sql.replaceFirst("\\?", "缺失");
+                    //}
                 }
             }
         }