MybatisPlus性能分析插件
生活随笔
收集整理的這篇文章主要介紹了
MybatisPlus性能分析插件
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
性能分析
性能分析攔截器,用于輸出每條 SQL 語句及其執行時間
SQL 性能執行分析,開發環境使用,超過指定時間,停止運行。有助于發現問題
配置插件
(1)參數說明
參數:maxTime: SQL 執行最大時長,超過自動停止運行,有助于發現問題。
參數:format: SQL是否格式化,默認false。
(2)在 MybatisPlusConfig 中配置
/*** SQL 執行性能分析插件* 開發環境使用,線上不推薦。 maxTime 指的是 sql 最大執行時長** 三種環境* * dev:開發環境* * test:測試環境* * prod:生產環境*/ @Bean @Profile({"dev","test"})// 設置 dev test 環境開啟 public PerformanceInterceptor performanceInterceptor() {PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor();performanceInterceptor.setMaxTime(500);//ms,超過此處設置的ms則sql不執行performanceInterceptor.setFormat(true);return performanceInterceptor; }(3)Spring Boot 中設置dev環境
#環境設置:dev、test、prod spring.profiles.active=dev可以針對各環境新建不同的配置文件application-dev.properties、application-test.properties、application-prod.properties
也可以自定義環境名稱:如test1、test2
測試
(1)常規測試
/*** 測試 性能分析插件*/ @Test public void testPerformance() {User user = new User();user.setName("我是Helen");user.setEmail("helen@sina.com");user.setAge(18);userMapper.insert(user); }(2)將maxTime 改小之后再次進行測試
performanceInterceptor.setMaxTime(5);//ms,超過此處設置的ms不執行如果執行時間過長,則拋出異常:The SQL execution time is too large,?
其它
如果想進行復雜條件查詢,那么需要使用條件構造器 Wapper,涉及到如下方法
1、delete
2、selectOne
3、selectCount
4、selectList
5、selectMaps
6、selectObjs
7、update
?
總結
以上是生活随笔為你收集整理的MybatisPlus性能分析插件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MybatisPlus实现逻辑删除
- 下一篇: MybatisPlus实现条件查询