spring集成mybatis后,打印SQL语句

网上说mybatis的早前版本配置打印sql还比较简单,在3.0.6之后配置方式修改了。

现在的spring-mybatis.xml配置如下:

<

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

mybatis-config.xml:

[
复制代码

](javascript:void(0); "复制代码")

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

[
复制代码

](javascript:void(0); "复制代码")

不错,打印SQL只需要加一个setting就可以了。

mybatis的日志打印方式比较多,SLF4J | LOG4J | LOG4J2 | JDK_LOGGING | COMMONS_LOGGING | STDOUT_LOGGING | NO_LOGGING,可以根据自己的需要进行配置

settings的更多参数可以参考官网文档:http://www.mybatis.org/mybatis-3/zh/configuration.html#settings

你可能感兴趣的:(spring集成mybatis后,打印SQL语句)