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;
    }
}
相关推荐
逆境不可逃9 小时前
Hello-Agents 第二部分-第六章:框架开发实践
java·人工智能·分布式·学习·架构·rabbitmq
我不是8神9 小时前
面试题:Gorutine泄露的条件有哪些?
java·开发语言
爱好物理的一名程序员XiaoK9 小时前
搭建网站时遇到的只显示空白界面
java
AC赳赳老秦9 小时前
OpenClaw与思维导图工具联动:自动生成工作规划脑图、拆解任务节点,适配职场管理
java·大数据·服务器·数据库·python·php·openclaw
吴声子夜歌10 小时前
状态机——枚举实现简单状态机
java·枚举·状态机
Rick199310 小时前
【无标题】
java
yoyo_zzm10 小时前
四大编程技术对比:PHP、Java、Python与HTML
java·python·php
IronMurphy10 小时前
Redis拷打第六讲
redis·spring·mybatis
海兰10 小时前
【第54篇】Graph + Langfuse 可观测性实战
java·人工智能·spring boot·spring ai