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;
    }
}
相关推荐
西柚小萌新44 分钟前
【人工智能:LangGraph】--3.控制流(Edge)
java·服务器·数据库
金銀銅鐵1 小时前
带您看懂字节码指令(八):数组里有什么
java·jvm·后端
r_oo_ki_e_3 小时前
牛牛与切割机
java·算法
Rain的Java大神之路3 小时前
Spring Boot 3 升级实战:真正吃掉工期的,是 MyBatis-Plus 坐标和 Security 6 重写
java·后端·面试
泡海椒3 小时前
Java PDF 报表开发:一页简历的两种版式风格对比与折行避坑
java·开发语言·pdf
wuminyu3 小时前
OpenJDK学习笔记:Native事件队列与Java回调背压
java·linux·c语言·jvm·c++
源码_空间4 小时前
基于Springboot在线考试系统(源码+文档)
java·spring boot·后端
@SmartSi4 小时前
AgentScope Java 入门 14:如何使用 PlanNotebook 让智能体学会“先规划,后执行“
java·agentscope
AI开源软件5 小时前
用MQTT跑通一台模拟设备:看懂IoT产品、物模型和告警
java·vue.js·spring boot·物联网·mqtt·iot·企业管理
__万波__6 小时前
嵌入式存储技术--1.Flash物理存储
java·开发语言