SpringBoot+MyBatis打印SQL

方法一

在springBoot+Mybatis日打印SQL的最简单方法就是在对应application.properties中添加:

logging.level.com.consumer.dao=DEBUG

注: com.consumer.service.impl 是 mybatis 接口及映射文件包。

但是对于 mybatis 的 xml 文件使用命名空间的情况下,这种方式不能打印SQL,那么可以参照方法二。

方法二

在SpringBoot对应application.properties中增加mybatis配置:

注意这个路径不能出错,不然会报错。

mybatis.config-location=classpath:mybatis-config.xml

在对应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>
        <setting name="logImpl" value="STDOUT_LOGGING"/>
    </settings>
</configuration>

猜你喜欢

转载自blog.csdn.net/qq_37502106/article/details/80756921
今日推荐