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;
    }
}
相关推荐
戴西软件12 小时前
戴西软件入选2026年安徽省制造业数智化转型服务商名单
java·大数据·服务器·前端·人工智能
爱棋笑谦13 小时前
springboot—数据源相关配置
java·spring boot·spring
budingxiaomoli21 小时前
Spring IoC &DI
java·spring·ioc·di
Spider Cat 蜘蛛猫21 小时前
Springboot SSO系统设计文档
java·spring boot·后端
未若君雅裁21 小时前
MySQL高可用与扩展-主从复制读写分离分库分表
java·数据库·mysql
月落归舟21 小时前
一篇文章了解Redis内存淘汰机制与过期Key清理
数据库·redis·mybatis
学习中.........21 小时前
从扰动函数的变化,感受红黑树带来的性能提升
java
计算机安禾1 天前
【c++面向对象编程】第24篇:类型转换运算符:自定义隐式转换与explicit
java·c++·算法
weixin199701080161 天前
【保姆级教程】淘宝/天猫商品详情 API(item_get)接入指南:Python/Java/PHP 调用示例与 JSON 返回值解析
java·python·php
环流_1 天前
redis核心数据类型在java中的操作
java·数据库·redis