mybatis sql 拦截器

SqlLogInterceptor

复制代码
@Component
@Intercepts({
        @Signature(type = StatementHandler.class, method = "query", args = {Statement.class, ResultHandler.class}),
        @Signature(type = StatementHandler.class, method = "update", args = {Statement.class})
})
@Slf4j
public class SqlLogInterceptor implements Interceptor {

    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        long startTime = System.currentTimeMillis();
        Object retVal = invocation.proceed();
        try {
            long endTime = System.currentTimeMillis();
            long time = endTime - startTime;
            String traceId = TraceIdUtil.getTraceId();
            if (StringUtils.isNotEmpty(traceId)) {
                log.info("time" + time);
            }
        }catch (Exception e){
            log.error("error", e);
        }
        return retVal;
    }
}
相关推荐
2601_949816224 小时前
Redis 配置日志
java
遇见你...4 小时前
A01-Spring概述
java·后端·spring
Via_Neo7 小时前
JAVA中以2为底的对数表示方式
java·开发语言
孟章豪7 小时前
《SQL拼接 vs 参数化,为什么公司禁止拼接SQL?(附真实案例)》
服务器·数据库·sql
野生技术架构师8 小时前
一线大厂Java面试八股文全栈通关手册(含源码级详解)
java·开发语言·面试
廋到被风吹走8 小时前
【AI】Codex 多语言实测:Python/Java/JS/SQL 效果横评
java·人工智能·python
tERS ERTS8 小时前
MySQL中查看表结构
java
坊钰8 小时前
Java 死锁问题及其解决方案
java·开发语言·数据库
于先生吖8 小时前
SpringBoot+MQTT 无人健身房智能管控系统源码实战
java·spring boot·后端
仍然.9 小时前
算法题目---模拟
java·javascript·算法