如何讓SpringBoot工程在log/控制檯中實時打印MyBatis執行的SQL語句

 

其實就是一句話設置的事情,實現步驟:app

在application.properties中書寫ide

logging.level.com.ufo.gatling.mapper.EmpMapper=debugdebug

這樣一行,其中com.ufo.gatling.mapper.EmpMapper爲我工程中與DB交互的類it

 

以後執行起來,就能看到SQL輸出了,示例以下:io

04-29 15:56:53.030 - ==>  Preparing: select b.* from (select a.*,rownum as rn from (select * from hy_emp order by id) a where rownum<101) b where b.rn>90 
2020-04-29 15:56:53.102 - ==> Parameters: 
2020-04-29 15:56:53.135 - <==      Total: 10
2020-04-29 15:56:53.138 - ==>  Preparing: select count(*) from hy_emp 
2020-04-29 15:56:53.138 - ==> Parameters: 
2020-04-29 15:56:53.144 - <==      Total: 1
2020-04-29 15:57:15.018 - ==>  Preparing: select b.* from (select a.*,rownum as rn from (select * from hy_emp order by id) a where rownum<111) b where b.rn>100 
2020-04-29 15:57:15.019 - ==> Parameters: 
2020-04-29 15:57:15.030 - <==      Total: 10
2020-04-29 15:57:15.031 - ==>  Preparing: select count(*) from hy_emp 
2020-04-29 15:57:15.032 - ==> Parameters: 
2020-04-29 15:57:15.036 - <==      Total: 1
2020-04-29 15:57:16.744 - ==>  Preparing: select b.* from (select a.*,rownum as rn from (select * from hy_emp order by id) a where rownum<101) b where b.rn>90 
2020-04-29 15:57:16.744 - ==> Parameters: 
2020-04-29 15:57:16.754 - <==      Total: 10
2020-04-29 15:57:16.755 - ==>  Preparing: select count(*) from hy_emp 
2020-04-29 15:57:16.755 - ==> Parameters: 
2020-04-29 15:57:16.760 - <==      Total: 1

相對於舊版本的SQL與參數分離,當前工程的SQL是一塊兒輸出了,這點改進不錯。class

--2020-04-29-- select

相關文章
相關標籤/搜索