spring集成mybatis後,打印SQL語句

網上說mybatis的早前版本配置打印sql還比較簡單,在3.0.6以後配置方式修改了。html

 

如今的spring-mybatis.xml配置以下:spring

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="configLocation" value="classpath:conf/mybatis-config.xml"></property>
        <!-- 自動掃描mapping.xml文件 -->
        <property name="mapperLocations" value="classpath:com/cyber/vip/dao/*.xml"></property>
    </bean>

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>
        <!-- 打印查詢語句 -->
        <setting name="logImpl" value="STDOUT_LOGGING" />
    </settings>
    
    <!-- mapper已經在spring-mybatis.xml中的sqlSessionFactory配置,這裏再也不須要配置 -->
<!--     <mappers> -->
<!--         <mapper resource="com/a/b/c/dao/BusinessInfoDaoMapper.xml" /> -->
<!--     </mappers> -->
</configuration>

 

不錯,打印SQL只須要加一個setting就能夠了。mybatis

mybatis的日誌打印方式比較多,SLF4J | LOG4J | LOG4J2 | JDK_LOGGING | COMMONS_LOGGING | STDOUT_LOGGING | NO_LOGGING,能夠根據本身的須要進行配置app

 

settings的更多參數能夠參考官網文檔:http://www.mybatis.org/mybatis-3/zh/configuration.html#settingsspa

相關文章
相關標籤/搜索