您的位置:宽带测速网 > 网络知识 > springboot mybatis打印sql语句怎么配置

springboot mybatis打印sql语句怎么配置

2025-06-17 09:47来源:互联网 [ ]

在Spring Boot项目中使用MyBatis打印SQL语句有两种常用的配置方式:

    使用MyBatis的配置文件配置:在MyBatis的配置文件(通常是mybatis-config.xml)中添加如下配置:
<settings><setting name="logImpl" value="LOG4J2"/></settings>

这样就可以将SQL语句打印到日志中。

    使用Spring Boot的配置文件配置:在application.properties或application.yml中添加如下配置:
mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl

这样也可以将SQL语句打印到控制台中。

通过以上配置,可以在控制台或日志中看到MyBatis执行的SQL语句,方便调试和优化SQL。