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;
    }
}
相关推荐
pshdhx_albert4 小时前
AI agent实现打字机效果
java·http·ai编程
沉鱼.444 小时前
第十二届题目
java·前端·算法
赫瑞5 小时前
数据结构中的排列组合 —— Java实现
java·开发语言·数据结构
周末也要写八哥6 小时前
多进程和多线程的特点和区别
java·开发语言·jvm
惜茶7 小时前
vue+SpringBoot(前后端交互)
java·vue.js·spring boot
杰克尼8 小时前
springCloud_day07(MQ高级)
java·spring·spring cloud
NHuan^_^9 小时前
SpringBoot3 整合 SpringAI 实现ai助手(记忆)
java·人工智能·spring boot
前进的李工9 小时前
MySQL大小写规则与存储引擎详解
开发语言·数据库·sql·mysql·存储引擎
Mr_Xuhhh9 小时前
从ArrayList到LinkedList:理解链表,掌握Java集合的另一种选择
java·数据结构·链表
错把套路当深情10 小时前
Java 全方向开发技术栈指南
java·开发语言