如何让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

相关文章
相关标签/搜索