java比net core性能好_关于 mybatis plus 性能分析插件 PerformanceInterceptor

 在平时我们使用 mybatis plus 的日志打印配置一般都是

mybatis-plus:

  configuration:

    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

这种方式打印出来的 sql 日志太长太繁琐,有时候太长也不是件好事,今日就安利一种非常清晰的 sql 日志打印。

d91f5b92fd427e8efecde5b30a498289.png

  • 今日安利好物:Mybatis Plus 的 PerformanceInterceptor

  • PerformanceInterceptor 是什么?

    PerformanceInterceptor 是 mybatis plus 的一个性能分析拦截器,用于输出每条 SQL 语句及其执行时间。

  • PerformanceInterceptor 有什么作用?

    性能分析拦截器,用于输出每条 SQL 语句及其执行时间

    参数:maxTime SQL 执行最大时长,超过自动停止运行,有助于发现问题。
    参数:format SQL

  • 是否格式化,默认false。

01

配置使用 PerformanceInterceptor 性能分析插件

我们只需要新增一个 mybatis plus 的配置类,注入 PerformanceInterceptor bean 就可以了

@Configurationpublic class MybatisPlusConfig {
        /**     * 打印 sql     */    @Bean    @Profile({
    "dev","pro"})// 设置 dev pro 环境开启日志打印    public PerformanceInterceptor performanceInterceptor() {
            PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor();        //格式化sql语句        Properties properties = new Properties();        properties.setProperty("format", "false");        performanceInterceptor.setProperties(properties);        return performanceInterceptor;    }}

配置好之后,请求一个带有查询和插入的方法,控制台会输出最终执行的 sql 和 执行时间

效果图:

8379360c4e402bb795d94aec5e4e3d36.png

02

关于 PerformanceInterceptor 的坑

关于 PerformanceInterceptor 版本问题

问题:3.2 无法使用此性能分析插件,导包时无法导入

原因:如果 mp 在3.1版本时使用是不会有问题的,但是如果你的 mp 是3.2的版本,就无法使用这个插件了,因为 mp 在3.2的版本已经移除了这个性能分析插件并推荐使用第三方插件。

3.1 源码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值