Spring整合Mybatis SQL語句的輸出
阿新 • • 發佈:2019-01-07
【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"Spring-Mybatis></property> 5 <-- 配置mapping檔案路徑--> 6 <property name="mapperLocations" value="classpath:/mapping/*.xml"/> 7 </bean>
【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
最後大功告成