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;
    }
}
相关推荐
悟能不能悟4 小时前
Elastic Stack 中两种主要查询语言 KQL (Kibana Query Language) 和 Lucene 的详细对比和解释。
java·开发语言
小马爱打代码4 小时前
MyBatis:SQL执行模块详解
mybatis
我是一只小青蛙8884 小时前
Java连接MySQL数据库实战指南
java
夏末4724 小时前
Java异常处理终极指南:从入门到企业级实战,让程序稳如老狗!
java·java ee
子非鱼9214 小时前
SpringBoot快速上手
java·spring boot·后端
techzhi4 小时前
Apifox CLI + GitLab CI:接口自动化测试实施记录
java·ci/cd·kubernetes·gitlab·yapi·运维开发·fastapi
我爱娃哈哈4 小时前
SpringBoot + XXL-JOB + Quartz:任务调度双引擎选型与高可用调度平台搭建
java·spring boot·后端
么么...4 小时前
MySQL 存储引擎与索引深度解析:从原理到优化实践
数据库·经验分享·sql·mysql
小宇的天下4 小时前
Synopsys Technology File and Routing Rules Reference Manual (1)
java·服务器·前端
Coder_Boy_5 小时前
基于SpringAI的在线考试系统-AI智能化拓展
java·大数据·人工智能·spring boot