Spring Boot 配置MyBatis 显示SQL日志
Posted 在奋斗的大道
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spring Boot 配置MyBatis 显示SQL日志相关的知识,希望对你有一定的参考价值。
刚刚在IDEA 编辑器上集成SQL Params Setter SQL格式化插件,需要控制台输出MyBatis sql 语句。
打印SQL语句的配置非常简单
在application.properties或application.yml文件中配置对应mapper所在包的日志级别即可。
示列:com.zzg.mapper 指向mapper 接口包路径地址
# 日志记录输出配置
logging.level.com.zzg.mapper=debug
控制台效果展示:
2022-04-21 17:07:45.577 INFO 12036 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Completed initialization in 4 ms
2022-04-21 17:07:45.606 DEBUG 12036 --- [nio-8080-exec-2] com.zzg.mapper.UserMapper.selectAll : ==> Preparing: select id, account, `name`, passwd, create_dt, create_by, update_dt, update_by, `state` from house_user
2022-04-21 17:07:45.687 DEBUG 12036 --- [nio-8080-exec-2] com.zzg.mapper.UserMapper.selectAll : ==> Parameters:
2022-04-21 17:07:45.706 DEBUG 12036 --- [nio-8080-exec-2] com.zzg.mapper.UserMapper.selectAll : <== Total: 0
2022-04-21 17:07:49.316 DEBUG 12036 --- [nio-8080-exec-1] com.zzg.mapper.UserMapper.selectAll : ==> Preparing: select id, account, `name`, passwd, create_dt, create_by, update_dt, update_by, `state` from house_user
2022-04-21 17:07:49.317 DEBUG 12036 --- [nio-8080-exec-1] com.zzg.mapper.UserMapper.selectAll : ==> Parameters:
2022-04-21 17:07:49.318 DEBUG 12036 --- [nio-8080-exec-1] com.zzg.mapper.UserMapper.selectAll : <== Total: 0
2022-04-21 17:07:51.311 DEBUG 12036 --- [nio-8080-exec-3] com.zzg.mapper.UserMapper.selectAll : ==> Preparing: select id, account, `name`, passwd, create_dt, create_by, update_dt, update_by, `state` from house_user
2022-04-21 17:07:51.311 DEBUG 12036 --- [nio-8080-exec-3] com.zzg.mapper.UserMapper.selectAll : ==> Parameters:
2022-04-21 17:07:51.312 DEBUG 12036 --- [nio-8080-exec-3] com.zzg.mapper.UserMapper.selectAll : <== Total: 0
使用SQL Params Setter 格式化SQL语句,提取相关联的SQL 语句。
打开一个文本编辑器,粘贴格式后的SQL语句。
IDEA 集成SQL Params Setter SQL 语句格式化插件
1、打开setting,找到Plugins选项(安装SQL Params Setter 插件(如果有就跳过这一步))
检索:SQL Params Setter
以上是关于Spring Boot 配置MyBatis 显示SQL日志的主要内容,如果未能解决你的问题,请参考以下文章
spring-boot结合mybatis-spring的一个例子
springboot - SqlSessionFactoryBean falls in circular dependencies by Spring Boot's DataSourceIni