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;
    }
}
相关推荐
Jesse_EC35 分钟前
为什么我设置的 contentLength 到了消费端变成了 0?
java
vipxieliang35 分钟前
ValidX 的 Date 和 DateTime vs JPA 的 Temporal 对比
java·后端
杜touch37 分钟前
Spring框架的AnnotationConfigApplicationContext类启动的流程
java
茉莉玫瑰花茶1 小时前
SQL 调优 [ 1 ]
数据库·sql
Databend1 小时前
从传统分区到微分区,Snowflake 与 Databend 如何减少数据扫描
大数据·数据库·sql
AI人工智能+电脑小能手1 小时前
大白话说Java设计模式-26-策略模式(业务实战篇)
java·spring·设计模式·策略模式·支付系统·算法切换
不是光头 强2 小时前
Java 后端 AI 技术选型与学习路线
java·人工智能·学习
不会叫的狼2 小时前
sql基础
sql
paopaokaka_luck2 小时前
基于springboot3+vue3的文山民族文化资源展示与推广平台(协同过滤算法、Echarts 图形化分析)
java·前端·spring boot·学习·echarts
eralong2 小时前
Java IO 与 NIO
java·后端