Mybatis怎么能看是否执行了sql语句
2个回答
展开全部
配置如下
在pom中增加如下依赖:
<dependency>
<groupId>org.bgee.log4jdbc-log4j2</groupId>
<artifactId>log4jdbc-log4j2-jdbc4.1</artifactId>
<version>1.16</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.13</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.13</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.0-beta9</version>
</dependency>
log4j.properties 如下配置 log4j.rootLogger=debug,stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
#log4j.appender.stdout.Target=System.err
log4j.appender.stdout.layout=org.apache.log4j.SimpleLayout
增加一个 log4jdbc.log4j2.prpperties 内容如下:
dbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator
log4jdbc.debug.stack.prefix=
log4jdbc.sqltiming.warn.threshold=
log4jdbc.sqltiming.error.threshold=
log4jdbc.dump.booleanastruefalse=
log4jdbc.dump.sql.maxlinelength=
log4jdbc.dump.fulldebugstacktrace=
log4jdbc.statement.warn=
log4jdbc.dump.sql.select=
log4jdbc.dump.sql.insert=
log4jdbc.dump.sql.update=
log4jdbc.dump.sql.delete=
log4jdbc.dump.sql.create=
log4jdbc.dump.sql.addsemicolon=
log4jdbc.auto.load.popular.drivers=
log4jdbc.trim.sql=
log4jdbc.trim.sql.extrablanklines=
log4jdbc.suppress.generated.keys.exception=
log4jdbc.drivers=
最后在mybatis的全局配置文件中
<dataSource type="POOLED">
<property name="driver" value="net.sf.log4jdbc.sql.jdbcapi.DriverSpy" />
<property name="url" value="jdbc:log4jdbc:mysql://localhost:3306/test" />
<property name="username" value="root" />
<property name="password" value="" />
</dataSource>
在pom中增加如下依赖:
<dependency>
<groupId>org.bgee.log4jdbc-log4j2</groupId>
<artifactId>log4jdbc-log4j2-jdbc4.1</artifactId>
<version>1.16</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.13</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.13</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.0-beta9</version>
</dependency>
log4j.properties 如下配置 log4j.rootLogger=debug,stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
#log4j.appender.stdout.Target=System.err
log4j.appender.stdout.layout=org.apache.log4j.SimpleLayout
增加一个 log4jdbc.log4j2.prpperties 内容如下:
dbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator
log4jdbc.debug.stack.prefix=
log4jdbc.sqltiming.warn.threshold=
log4jdbc.sqltiming.error.threshold=
log4jdbc.dump.booleanastruefalse=
log4jdbc.dump.sql.maxlinelength=
log4jdbc.dump.fulldebugstacktrace=
log4jdbc.statement.warn=
log4jdbc.dump.sql.select=
log4jdbc.dump.sql.insert=
log4jdbc.dump.sql.update=
log4jdbc.dump.sql.delete=
log4jdbc.dump.sql.create=
log4jdbc.dump.sql.addsemicolon=
log4jdbc.auto.load.popular.drivers=
log4jdbc.trim.sql=
log4jdbc.trim.sql.extrablanklines=
log4jdbc.suppress.generated.keys.exception=
log4jdbc.drivers=
最后在mybatis的全局配置文件中
<dataSource type="POOLED">
<property name="driver" value="net.sf.log4jdbc.sql.jdbcapi.DriverSpy" />
<property name="url" value="jdbc:log4jdbc:mysql://localhost:3306/test" />
<property name="username" value="root" />
<property name="password" value="" />
</dataSource>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询