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;
    }
}
相关推荐
带刺的坐椅4 分钟前
jFinal 使用 SolonMCP 开发 MCP(拥抱新潮流)
java·ai·solon·jfinal·mcp
陌尘(MoCheeen)25 分钟前
技术书籍推荐(002)
java·javascript·c++·python·go
牛马baby26 分钟前
Java高频面试之并发编程-16
java·开发语言·面试
cainiao08060526 分钟前
《Spring Boot 4.0新特性深度解析》
java·spring boot·后端
zizisuo37 分钟前
面试篇:Spring MVC
java·spring·mvc
-曾牛38 分钟前
Spring AI 与 Hugging Face 深度集成:打造高效文本生成应用
java·人工智能·后端·spring·搜索引擎·springai·deepseek
Brookty1 小时前
【Java学习】Lambda表达式
java·学习
孤寂大仙v1 小时前
【Linux笔记】——进程信号的保存
java·linux·笔记
饕餮争锋1 小时前
feign.RequestInterceptor 简介-笔记
java·开发语言·笔记
计算机学姐2 小时前
基于SpringBoot的小区停车位管理系统
java·vue.js·spring boot·后端·mysql·spring·maven