網(wǎng)上說mybatis的早前版本配置打印sql還比較簡單,在3.0.6之后配置方式修改了伦腐。
現(xiàn)在的spring-mybatis.xml配置如下:
<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">
<
bean
id
="sqlSessionFactory"
class
="org.mybatis.spring.SqlSessionFactoryBean"
<
property
name
="dataSource"
ref
="dataSource"
/>
<
property
name
="configLocation"
value
="classpath:conf/mybatis-config.xml"
</
property
<
property
name
="mapperLocations"
value
="classpath:com/cyber/vip/dao/*.xml"
</
property
</
bean
</pre>
mybatis-config.xml:
[](javascript:void(0); "復制代碼")
<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">
<?
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
</pre>
[](javascript:void(0); "復制代碼")
不錯灭将,打印SQL只需要加一個setting就可以了疼鸟。
mybatis的日志打印方式比較多,SLF4J | LOG4J | LOG4J2 | JDK_LOGGING | COMMONS_LOGGING | STDOUT_LOGGING | NO_LOGGING庙曙,可以根據(jù)自己的需要進行配置
settings的更多參數(shù)可以參考官網(wǎng)文檔:http://www.mybatis.org/mybatis-3/zh/configuration.html#settings