mybatis的sql日志

Mybatis中的sql日志打印,快速分析出sql的错误。

项目使用的是mybatis的springboot框架,日志的输出基于log4j,所以先要引入依赖

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<!-- 忽略自带的日志框架. -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- log4j. -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j</artifactId>
</dependency>

在配置文件application.yml中配置日志输出

1
2
3
1 logging:
2 level:
3 com.example.mapper: trace

或者在application.properties中配置

1
logging.level.main.blog.mapper=debug