首页 > 其他分享 >05-性能分析插件

05-性能分析插件

时间:2022-10-26 16:25:04浏览次数:57  
标签:插件 05 性能 dev performanceInterceptor sql test PerformanceInterceptor

我们在平时的开发中,会遇到一些满Sql。测试、druid···
MybatisPlus也提供了性能分析插件,如果超过这个时间就停止运行!

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

  1. 导入插件
//性能分析插件
@Bean
@Profile({"dev","test"})//设置dev开发、test测试 环境开启  保证我们的效率
public PerformanceInterceptor performanceInterceptor(){
    PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor();
    performanceInterceptor.setMaxTime(100);//设置sql最大执行时间*ms,如果超过了则不执行
    performanceInterceptor.setFormat(true);//开启sql格式化
    return performanceInterceptor;
}

注意: 要在SpringBoot中配置环境为dev或test环境!

spring:
  # 开发者模式
  profiles:
    active: dev
  1. 测试
@Test
void contextLoads() {
    //参数是一个wrapper ,条件构造器,这里我们先不用 null
    //查询全部的用户
    List<User> userList = userMapper.selectList(null);
    userList.forEach(System.out::println);
}

image.png
使用性能分析插件,可以帮助我们提高效率!、

标签:插件,05,性能,dev,performanceInterceptor,sql,test,PerformanceInterceptor
From: https://www.cnblogs.com/lengyingmofeng/p/16828804.html

相关文章