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;
    }
}
相关推荐
漫谈网络10 分钟前
sqlite3 命令行工具详细介绍
sql·sqlite·db
程序员小假19 分钟前
说一说 SpringBoot 中 CommandLineRunner
java·后端
sky_ph28 分钟前
JAVA-GC浅析(一)
java·后端
爱coding的橙子29 分钟前
每日算法刷题Day24 6.6:leetcode二分答案2道题,用时1h(下次计时20min没写出来直接看题解,节省时间)
java·算法·leetcode
岁忧34 分钟前
(nice!!!)(LeetCode每日一题)2434. 使用机器人打印字典序最小的字符串(贪心+栈)
java·c++·算法·leetcode·职场和发展·go
天天摸鱼的java工程师43 分钟前
@Autowired 注入失效?
java·后端
sss191s1 小时前
校招 Java 面试基础题目解析学习指南含新技术实操要点
java·python·面试
编程毕设1 小时前
【含文档+PPT+源码】基于微信小程序的旅游论坛系统的设计与实现
java·tomcat·旅游
爱吃土豆的马铃薯ㅤㅤㅤㅤㅤㅤㅤㅤㅤ1 小时前
saveOrUpdate 有个缺点,不会把值赋值为null,解决办法
java·开发语言
bytebeats1 小时前
Java 21 虚拟线程 - 兄嘚, 我的锁呢?
java