|
@@ -1,5 +1,6 @@
|
|
|
package com.zd.security.config;
|
|
package com.zd.security.config;
|
|
|
|
|
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.ibatis.mapping.MappedStatement;
|
|
import org.apache.ibatis.mapping.MappedStatement;
|
|
|
import org.apache.ibatis.plugin.*;
|
|
import org.apache.ibatis.plugin.*;
|
|
|
|
|
|
|
@@ -9,17 +10,18 @@ import org.apache.ibatis.executor.Executor;
|
|
|
@Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class}),
|
|
@Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class}),
|
|
|
@Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class})
|
|
@Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class})
|
|
|
})
|
|
})
|
|
|
|
|
+@Slf4j(topic = "sql-interceptor---")
|
|
|
public class SqlCostInterceptor implements Interceptor {
|
|
public class SqlCostInterceptor implements Interceptor {
|
|
|
@Override
|
|
@Override
|
|
|
public Object intercept(Invocation invocation) throws Throwable {
|
|
public Object intercept(Invocation invocation) throws Throwable {
|
|
|
long startTime = System.currentTimeMillis();
|
|
long startTime = System.currentTimeMillis();
|
|
|
Object result = invocation.proceed();
|
|
Object result = invocation.proceed();
|
|
|
long endTime = System.currentTimeMillis();
|
|
long endTime = System.currentTimeMillis();
|
|
|
- long costTime = endTime - startTime;
|
|
|
|
|
|
|
+ long costTime = (endTime - startTime) / 1000;
|
|
|
|
|
|
|
|
MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0];
|
|
MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0];
|
|
|
String sqlId = mappedStatement.getId();
|
|
String sqlId = mappedStatement.getId();
|
|
|
- System.out.println("SQL 执行耗时:" + costTime + "ms, SQL ID: " + sqlId);
|
|
|
|
|
|
|
+ log.info("The sql execution took {} seconds, SQL ID: {}" ,costTime, sqlId);
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|