SpringBoot 如何打印mybatis的执行sql

1、使用场景
       应为在开发过程之中跟踪后端SQL语句,因什么原因导致的错误。需要在Debug过程之中打印出执行的SQL语句。所以需要配置一下SpringBoot之中,Mybatis打印SQL语句。 

2、具体实现
      application.properties(yml)中配置的两种方式:    

   1. logging.level.dao包名(dao package)=debug
 
   2. mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl

2.1、方案一 打印所有mybatis SQL
一下是yaml文件配置,properties文件翻译一下即可

mybatis
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl 

2.2、指定mapper文件所在的包
logging:
  level:
    cn.com.demos.*.mapper: trace # 改成你的mapper文件所在包路径

 

比如我采用第二种方式如下:

application.yml中 mybatis配置修改如下:

SpringBoot 如何打印mybatis的执行sql_第1张图片

 

SpringBoot 如何打印mybatis的执行sql_第2张图片

可以看到执行的效果如下:

 

你可能感兴趣的:(大数据,mybatis,SpringBoot,执行sql)