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;
    }
}
相关推荐
百***355110 小时前
什么是Spring Boot 应用开发?
java·spring boot·后端
謝堆堆DDD10 小时前
eclipse由只运行java文件到创建web项目
java·ide·eclipse
redtro9511 小时前
【开发备忘】GeoServer相关两则:发布时间维ImageMosaic+客户端WMS样式
java·开发语言·spring
q***581911 小时前
【SQL】MySQL中的字符串处理函数:concat 函数拼接字符串,COALESCE函数处理NULL字符串
数据库·sql·mysql
代码不停11 小时前
Java模拟算法题目练习
java·开发语言·算法
百***266311 小时前
Tomcat的server.xml配置详解
xml·java·tomcat
懒羊羊不懒@11 小时前
【MySQL | 基础】多表查询
数据库·sql·mysql
朝新_11 小时前
【统一功能处理】SpringBoot 统一功能专题:拦截器、数据封装、异常处理及 DispatcherServlet 源码初探
java·spring boot·后端·spring·javaee
恸流失11 小时前
集合练习1
java
LiLiYuan.11 小时前
Arrays类和List接口的关联
java·开发语言·windows·python