欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

MyBatisPlus插件扩展_PerformanceInterceptor性能分析插件的使用

发布时间:2025/3/19 编程问答 32 豆豆
生活随笔 收集整理的这篇文章主要介绍了 MyBatisPlus插件扩展_PerformanceInterceptor性能分析插件的使用 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

场景

项目搭建专栏:

https://blog.csdn.net/BADAO_LIUMANG_QIZHI/column/info/37194

简介

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

参数:maxTime SQL 执行最大时长,超过自动停止运行,有助于发现问题。
参数:format SQL SQL是否格式化,默认false。

实现

来到项目下的applicationContext.xml中配置sqlSessionFactoryBean的地方。

<bean id="sqlSessionFactoryBean" class="com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean"><!-- 数据源 --><property name="dataSource" ref="dataSource"></property><property name="configLocation" value="classpath:mybatis-config.xml"></property><!-- 别名处理 --><property name="typeAliasesPackage" value="com.badao.beans"></property> <!-- 注入全局MP策略配置 --><property name="globalConfig" ref="globalConfiguration"></property> <!-- 插件注册 --><property name="plugins"><list><!-- 注册分页插件 --><bean class="com.baomidou.mybatisplus.plugins.PaginationInterceptor"></bean><!-- 注册执行分析插件 --><bean class="com.baomidou.mybatisplus.plugins.SqlExplainInterceptor"><property name="stopProceed" value="true" /></bean><!-- 注册性能分析插件 --><bean class="com.baomidou.mybatisplus.plugins.PerformanceInterceptor"><!-- 单位为毫秒 --><property name="maxTime" value="100" /><!--SQL是否格式化 默认false--><property name="format" value="true" /></bean></list></property> </bean>

编写测试方法

/**** 性能分析插件*/@Testpublic void testPaginationInterceptor() {Employee employee = new Employee();employee.setName("PaginationInterceptor测试2");employee.setAge(23);employeeMapper.insert(employee);}

运行测试方法

然后把时间改短点再重新测试

源码下载

https://download.csdn.net/download/badao_liumang_qizhi/11147598

总结

以上是生活随笔为你收集整理的MyBatisPlus插件扩展_PerformanceInterceptor性能分析插件的使用的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。