MyBatis框架在控制台打印Sql语句-遁地龙卷风
第二版
(-1)写在前面
我用的是MyBatis 3.2.4,Maven Project
(0)mybatis-config.xml
<settings>
<setting name="logImpl" value="LOG4J"/>
</settings>
这个是可以省略的,当 mybatis-config.xml,log4j.properties同一目录下时。
(1)log4j.properties
内容
log4j.rootLogger=DEBUG, 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
log4j.logger.java.sql.PreparedStatement=DEBUG
b.位置
src/main/resources 下
(3)结果
2016-11-14 22:36:55,173 [main] DEBUG [com.world.mapper.UserMapper.insertUser] - ooo Using Connection [com.mysql.jdbc.JDBC4Connection@13805618]
2016-11-14 22:36:55,174 [main] DEBUG [com.world.mapper.UserMapper.insertUser] - ==> Preparing: insert into t_user( user_name,password,last_visit,credits ) values(?,?,?,?)
2016-11-14 22:36:55,227 [main] DEBUG [com.world.mapper.UserMapper.insertUser] - ==> Parameters: 王(String), 217020(String), 2016-11-14 22:36:54.966(Timestamp), 12(Integer)
2016-11-14 22:36:55,298 [main] DEBUG [com.world.mapper.UserMapper.insertUser] - <== Updates: 1