# 开启 Mybatis 日志 sql 打印

在 application.yml 中的 mybatis 中配置日志的实现

mybatis:
  type-aliases-package: cn.mrcode.foodiedev.pojo    # 实体层
  mapper-locations: classpath:mapper/*.xml          # mapper 层
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
1
2
3
4
5

我们配置了 log4j 在控制台打印日志的格式,这里只要选择将日志打印在控制台,就可以了。

需要注意的是:在生产环境一般是不开启的,只在开发或则测试环境开启。

打印的日志信息如下

==>  Preparing: SELECT id,username,password,nickname,realname,face,mobile,email,sex,birthday,created_time,updated_time FROM users WHERE ( ( username = ? and password = ? ) ) 
==> Parameters: test(String), 4QrcOUm6Wau+VuBX8g+IPg==(String)
<==    Columns: id, username, password, nickname, realname, face, mobile, email, sex, birthday, created_time, updated_time
<==        Row: 210213BX4KY0M5AW, test, 4QrcOUm6Wau+VuBX8g+IPg==, test, null, http://localhost:900/xx.jpg, null, null, 2, 1899-12-31, 2021-02-13 08:40:20, 2021-02-13 08:40:20
<==      Total: 1
1
2
3
4
5