性能分析插件
我們在平常的開發(fā)中逊彭,會遇到一些慢SQL。MP提供的性能分析插件匪燕,如果超過這個時間就會停止運行蕾羊!
作用:用于輸出每條sql語句及其執(zhí)行的時間
1、導(dǎo)入插件
@Configuration
@MapperScan("com.cm.mapper")
@EnableTransactionManagement // 增加事務(wù)管理
public class MybatisPlusConfig {
/**
* sql執(zhí)行效率插件
* @return
*/
@Bean
@Profile({"dev","test"})
public PerformanceInterceptor performanceInterceptor() {
PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor();
// 在工作中帽驯,不允許用戶等待
performanceInterceptor.setMaxTime(1); // ms 設(shè)置sql執(zhí)行的最大s時間,如果超過了則不執(zhí)行
performanceInterceptor.setFormat(true); // 是否進行格式化
return new PerformanceInterceptor();
}
}
記住龟再,要在springboot中配置環(huán)境為dev或者test環(huán)境
## 設(shè)置開發(fā)環(huán)境
spring.profiles.active=dev
2、測試使用
查詢測試
// 繼承了BaseMapper尼变,所有的方法都來自父類利凑,我們也可以編寫自己的擴展方法
@Test
void contextLoads() {
List<User> users = userMapper.selectList(null);
users.forEach(System.out::println);
}