随笔 - 301  文章 - 2  评论 - 16  阅读 - 34万

Mybatis 开启控制台打印sql语句

springboot+mybatis整合过程中,开启控制台sql语句打印的多种方式:
附:mybatis官方文档

方法一:

复制代码
1.在mybatis的配置文件中添加:

<settings>
<!-- 打印sql日志 -->
<setting name="logImpl" value="STDOUT_LOGGING" />
</settings>
mybatis的配置文件----mybatis-config.xml如下:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<!-- 打印sql日志 -->
<setting name="logImpl" value="STDOUT_LOGGING" />
</settings>
</configuration>
复制代码

 

2.在springboot的配置文件----appcation.yml中添加:

mybatis:
   configuration:
      log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

 


ps:

          IDEA中,springboot默认配置文件是application.properties文件,但是yml文件在语法上更加简洁,更有层次感,所以此处是用yml语法,properties中好像是这么写的:mybatis.configuration.log-impl= org.apache.ibatis.logging.stdout.StdOutImpl

控制台可以打印了。。。。。

 

方法二:
在springboot+mybatis整合中,可以将springboot的配置文件添加如下一段也可:

logging:
   level:
      com.lucifer.springboot.cache.mapper: debug

ps:  com.lucifer.springboot.cache.mapper是包名

方法三:
如果你使用的是springboot+mybatis-plus的话:

<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.3.1</version>
</dependency>
application.yml: 

mybatis-plus:
   configuration:
       log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

控制台打印: 

JDBC Connection [HikariProxyConnection@1006460161 wrapping com.mysql.cj.jdbc.ConnectionImpl@37cccae8] will not be managed by Spring
==> Preparing: SELECT id,user_name,age FROM user WHERE (user_name = ?)
==> Parameters: 张三(String)
<== Columns: id, user_name, age
<== Row: 1, 张三, 18
<== Total: 1
 

posted on   Code2020  阅读(15553)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示