Mybatis如何开启控制台打印sql语句
Mybatis开启控制台打印sql语句
springboot+mybatis整合过程中,开启控制台sql语句打印的多种方式:
方法一
1>(spring+mybatis)在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+mybatis)在springboot的配置文件----appcation.yml中添加:
mybatis:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImplps:
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
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
springCloud Gateway StripPrefix和PrefixPath过滤器的区别及说
这篇文章主要介绍了springCloud Gateway StripPrefix和PrefixPath过滤器的区别及说明,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教2025-06-06
intellij idea如何将web项目打成war包的实现
这篇文章主要介绍了intellij idea如何将web项目打成war包的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2020-07-07


最新评论