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;
    }
}
相关推荐
摇滚侠13 小时前
Maven 教程,Maven 安装及使用,5 小时上手 Maven 又快又稳
java·maven
倔强菜鸟13 小时前
2026.2.2--Jenkins的基本使用
java·运维·jenkins
hai742513 小时前
在 Eclipse 的 JSP 项目中引入 MySQL 驱动
java·mysql·eclipse
瑞雪兆丰年兮13 小时前
[从0开始学Java|第十一天]学生管理系统
java·开发语言
看世界的小gui13 小时前
Jeecgboot通过Maxkey实现单点登录完整方案
java·spring boot·jeecgboot
Arvin62713 小时前
IntelliJ IDEA:无法读取**.properties
java·intellij-idea
10km13 小时前
Spring Boot 环境下使用 Map<String, MultipartFile> 实现文件上传功能
java·spring boot·mock·map·multipartfile
学到头秃的suhian14 小时前
Java的锁机制
java
Amarantine、沐风倩✨14 小时前
一次线上性能事故的处理复盘:从 SQL 到扩容的工程化思路
java·数据库·sql·oracle
tb_first14 小时前
万字超详细苍穹外卖学习笔记1
java·jvm·spring boot·笔记·学习·tomcat·mybatis