在spring boot 中使用mybatis 想看到sql語句的運行情況。
雖然按照 之前說的配置了 logging.level.你的mapper包位置 = debug
但是依舊沒有起作用。
所以采用這種方式:
只需要相對於原來的項目修改兩步
1.加入引用
<!--打印sql-->
<dependency>
<groupId>com.googlecode.log4jdbc</groupId>
<artifactId>log4jdbc</artifactId>
<version>1.2</version>
</dependency>
2.appliaction.properties,修改 driver 驅動和 url 數據源地址,重啟項目即可
# 修改前 spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/springboot?useUnicode=true&characterEncoding=UTF-8 # 修改后 spring.datasource.driver-class-name=net.sf.log4jdbc.DriverSpy spring.datasource.url=jdbc:log4jdbc:mysql://localhost:3306/springboot?useUnicode=true&characterEncoding=UTF-8
完成!!!