05-性能分析插件

我们在平时的开发中,会遇到一些满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
使用性能分析插件,可以帮助我们提高效率!、

posted @ 2022-10-26 16:10  ゐ叶う枫ゆ  阅读(28)  评论(0编辑  收藏  举报