温馨提示×

springboot mybatis打印sql语句怎么配置

小亿
2175
2024-06-12 16:16:09
栏目: 云计算
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

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

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

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

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

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

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

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:SpringBoot中怎么集成MyBatis日志功能

0