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;
    }
}
相关推荐
码头整点薯条6 小时前
大数据量查询处理方案
java
菜鸟233号6 小时前
力扣474 一和零 java实现
java·数据结构·算法·leetcode·动态规划
天天摸鱼的java工程师6 小时前
工作中七天免登录如何实现
java·后端
q***44156 小时前
Java性能优化实战技术文章大纲Java性能优化的核心目标与原则
java·开发语言·性能优化
undsky6 小时前
【RuoYi-SpringBoot3-Pro】:多租户功能上手指南
spring boot·后端·mybatis
毕设源码-郭学长6 小时前
【开题答辩全过程】以 基于springbootvue图书馆选座系统设计与实现为例,包含答辩的问题和答案
java
鱼跃鹰飞6 小时前
怎么排查线上CPU100%的问题
java·jvm·后端
Seven976 小时前
剑指offer-62、⼆叉搜索树的第k个结点
java
invicinble6 小时前
关于写原创文章的思路分析
java·spring boot·spring
heartbeat..6 小时前
MySQL 索引从入门到精通:核心概念、类型与实战优化
java·数据库·mysql·索引