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;
    }
}
相关推荐
Coder_Boy_21 小时前
【人工智能应用技术】-基础实战-小程序应用(基于springAI+百度语音技术)智能语音控制-单片机交互代码
java·人工智能·后端·嵌入式硬件
Hello.Reader21 小时前
Flink SQL UPDATE 语句批模式行级更新、连接器能力要求与实战避坑
大数据·sql·flink
Hello.Reader21 小时前
Flink SQL CALL 语句调用存储过程做数据操作与运维任务(含 Java 示例 + 避坑指南)
运维·sql·flink
a努力。21 小时前
国家电网Java面试被问:二叉树的前序、中序、后序遍历
java·开发语言·后端·面试
yuniko-n21 小时前
【力扣 SQL 50】子查询篇
数据库·sql·leetcode
賬號封禁中miu1 天前
图论之最小生成树
java·数据结构·算法·图论
月明长歌1 天前
Java数据结构:PriorityQueue堆与优先级队列:从概念到手写大根堆
java·数据结构·python·leetcode·
lalala_Zou1 天前
小米日常实习一面
java·后端·面试
算法与双吉汉堡1 天前
【短链接项目笔记】Day3 用户模块剩余部分
java·redis·后端
Chengbei111 天前
fastjson 原生反序列化配合动态代理绕过限制
java·安全·网络安全·系统安全·安全架构