SpringBoot开发环境下开启mybatis日志控制台SQL打印

SpringBoot中关于Mybatis的原配置如下:

mybatis:
  # 配置MyBatis的XML配置文件位置
  mapper-locations: classpath:mapper/*.xml
  # 配置XML映射文件中指定的实体类别名路径
  type-aliases-package: com.company.project
  configuration:
    #springboot开启mybatis驼峰命名匹配映射
    map-underscore-to-camel-case: true

为了测试方便需要开启mybatis日志sql打印,只需要加 configuration: log-impl: org.apache.ibatis.logging.stdout.StdOutImpl配置即可在控制台中看到执行的sql。

mybatis:
  # 配置MyBatis的XML配置文件位置
  mapper-locations: classpath:mapper/*.xml
  # 配置XML映射文件中指定的实体类别名路径
  type-aliases-package: com.company.project
  configuration:
    #springboot开启mybatis驼峰命名匹配映射
    map-underscore-to-camel-case: true
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

重启项目,我们在控制台将看到配置生效:

...
itialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter.
Parsed mapper file: 'file [E:\Projects-Idea\project-springboot-changan-story\target\classes\mapper\AppMapper.xml]'
...

首次查询时,我们在控制台将看到更加详细的过程信息:

Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@22267dfc] was not registered for synchronization because synchronization is not active
Cache Hit Ratio [com.company.project.mapper.DivisionMapper]: 0.0
JDBC Connection [HikariProxyConnection@1205939973 wrapping com.mysql.cj.jdbc.ConnectionImpl@53918424] will not be managed by Spring
==>  Preparing: SELECT * FROM division where id IS NOT NULL and level_type = ? LIMIT ? , ?
==> Parameters: 1(Short), 0(Integer), 10(Integer)
<==    Columns: id, parent_id, code, name, short_name, merger_name, level_type, lng, lat, pin_yin, city_code, zip_code, serial_number, status, version, create_time, update_time
<==        Row: 110000, 100000, 110000, 北京, 北京, 中国,北京, 1, 116.405285, 39.904989, Beijing, 0, 0, 1, 0, 0, 2022-02-13 10:35:43, 2022-02-13 10:35:43
...
<==      Total: 10
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@22267dfc]

开启二级缓存的情况下,将看到下列信息:

Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7f3ec731] was not registered for synchronization because synchronization is not active
Cache Hit Ratio [com.company.project.mapper.DivisionMapper]: 0.5
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7f3ec731]

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

西安极客联盟

给作者送颗薄荷糖吧!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值