性能分析插件
我们在平时的开发中,会遇到一些慢Sql。测试、druid···
MybatisPlus也提供了性能分析插件,如果超过这个时间就停止运行!
性能分析拦截器作用:用于输出每条sql语句及其执行时间
1、导入插件
- config - MyBatisPlusConfig
//性能分析插件
@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
2、测试使用
@Test//通过id查询单个用户
public void testSelectById(){
User user = userMapper.selectById(1L);
System.out.println(user);
}
3.查看控制台
使用性能分析插件,可以帮助我们提高效率!