目录

前言

使用

效果


前言

如果你恰好使用 Mybatis-plus 框架,那么在开发环境就不能错过它提供的 PerformanceInterceptor 插件,该插件能打印 sql 执行时间以及完整的 sql 语句,非常方便复制出来分析 sql 

使用

这里使用的 Mybatis-plus 框架比较老,是 2.3 版本的,引入依赖,然后实例化 PerformanceInterceptor 插件即可(注意该插件在 3.2 版本以上被移除,可考虑使用 p6spy 分析插件),如下

<dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>2.3</version>
            <exclusions>
                <exclusion>
                    <artifactId>tomcat-jdbc</artifactId>
                    <groupId>org.apache.tomcat</groupId>
                </exclusion>
            </exclusions>
        </dependency>
@Bean
    @Profile({"dev", "test"})
    public PerformanceInterceptor performanceInterceptor() {
        PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor();
        performanceInterceptor.setMaxTime(15000);
        performanceInterceptor.setFormat(false);
        return performanceInterceptor;
    }

效果

此时打印出来的 sql 便不会带有 ?,而是拼接完参数后的完整 sql  

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐