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;
    }
}
相关推荐
NaMM CHIN5 小时前
sql实战解析-sum()over(partition by xx order by xx)
数据库·sql
OtIo TALL5 小时前
redis7 for windows的安装教程
java
2601_949817725 小时前
Spring Boot3.3.X整合Mybatis-Plus
spring boot·后端·mybatis
不瘦80斤不改名5 小时前
深入浅出 MySQL(一):一文理清 SQL 核心规范与五大分类
数据库·sql·mysql
uNke DEPH6 小时前
Spring Boot的项目结构
java·spring boot·后端
xixingzhe26 小时前
idea启动vue项目
java·vue.js·intellij-idea
wzl202612136 小时前
企业微信定时群发技术实现与实操指南(原生接口+工具落地)
java·运维·前端·企业微信
凌波粒6 小时前
Java 8 “新”特性详解:Lambda、函数式接口、Stream、Optional 与方法引用
java·开发语言·idea
曹牧6 小时前
Eclipse:悬停提示(Hover)
java·ide·eclipse
oyzz1207 小时前
Spring EL 表达式的简单介绍和使用
java·后端·spring