首页 > 其他分享 >MyBatisPlus插件扩展_PerformanceInterceptor性能分析插件的使用

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

时间:2023-03-24 18:00:43浏览次数:37  
标签:插件 MyBatisPlus 性能 Employee PerformanceInterceptor SQL employee 测试方法



简介

性能分析拦截器,用于输出每条 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>

编写测试方法

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

运行测试方法

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

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

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


标签:插件,MyBatisPlus,性能,Employee,PerformanceInterceptor,SQL,employee,测试方法
From: https://blog.51cto.com/BADAOLIUMANGQZ/6147638

相关文章