Spring整合Mybatis SQL语句的输出

【1.修改Spring-Mybatis】

1     <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
2         <property name="dataSource" ref="dataSource"/>
3         <-- 添加此行代码 ,并创建一个mybatis-config.xml-->
4         <property name="configLocation" value="classpath:mybatis-config.xml"></property>
5         <-- 配置mapping文件路径-->
6         <property name="mapperLocations" value="classpath:/mapping/*.xml"/>
7     </bean>
Spring-Mybatis

【2.创建Mybatis-config】

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

【3.配置log4j.properties】

log4j.rootLogger=DEBUG, Console

#Console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n

log4j.logger.java.sql.ResultSet=INFO
log4j.logger.org.apache=INFO
log4j.logger.java.sql.Connection=DEBUG
log4j.logger.java.sql.Statement=DEBUG

 

  最后大功告成

posted @ 2019-01-07 20:39  Cloverll  阅读(1538)  评论(0编辑  收藏  举报