Mybatis(3)SQL语句控制台打印

  • 2019 年 10 月 4 日
  • 筆記

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

本文链接:https://blog.csdn.net/qq_37933685/article/details/87972917

title: Mybatis(3)SQL语句控制台打印 date: 2019-02-27 12:00:00 +0800 update: 2019-02-27 12:00:00 +0800 author: me cover: https://ws1.sinaimg.cn/large/006jIRTely1g0kz9p2y8jj31hc0u0gs2.jpg preview: 使用Mybatis的时候,快速debug可以使用Mybatis的SQL debug 功能,快速定位SQL语句。快速debug tags:

  • MyBatis

Mybatis(3)SQL语句控制台打印

SpringMVC 配置

步骤

  1. 找到对应的sping的mybatis的配置文件,引入mybatis-config.xml
  2. 配置mybatis-config.xml

1.找到对应的sping的mybatis的配置文件,引入mybatis-config.xml

部分spring配置如下:

<!-- define the SqlSessionFactory -->      <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">          <property name="dataSource" ref="dataSource" />          <!-- 在这里引入> mybatis-config.xml -->          <property name="configLocation" value="classpath:mybatis-config.xml" />          <property name="typeAliasesPackage" value="com.***.mapper" />          <property name="mapperLocations">              <list>                  <!--<value>classpath*:*.xml</value>-->              </list>          </property>      </bean>

2.配置mybatis-config.xml

打开SQL打印的功能,配置文件全体如下,如果已有直接在响应的位置添加即可

<?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>

SpringBoot 配置

步骤

  1. 修改application.yml
mybatis:      configuration:        log-impl: org.apache.ibatis.logging.stdout.StdOutImpl