请教Mybatis中如何在程序中获取Mapper中定义的SQL语句
1个回答
2016-05-23 · 做真实的自己 用良心做教育
千锋教育
千锋教育专注HTML5大前端、JavaEE、Python、人工智能、UI&UE、云计算、全栈软件测试、大数据、物联网+嵌入式、Unity游戏开发、网络安全、互联网营销、Go语言等培训教育。
向TA提问
关注
展开全部
我把mybatis3.2的源码下载之后,把里面PooledDataSource类的log输出部分,换成log.warn之后,重新打jar包,放到项目中,日志级别改为info,如:
Java代码
log4j.rootLogger=info, stdout, R
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[service] %d - %c -%-4r [%t] %-5p %c %x - %m%n
log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.File=../logs/service.log
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=[service] %d - %c -%-4r [%t] %-5p %c %x - %m%n
log4j.logger.com.ibatis = debug
log4j.logger.com.ibatis.common.jdbc.SimpleDataSource = debug
log4j.logger.com.ibatis.common.jdbc.ScriptRunner = debug
log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate = debug
log4j.logger.java.sql.Connection = debug
log4j.logger.java.sql.Statement = debug
log4j.logger.java.sql.PreparedStatement = debug
log4j.logger.java.sql.ResultSet =debug
此时,info级别能够输出warn级别的日志,我的日志显示如下:
Java代码
[service] 2013-04-19 10:30:57,982 - org.apache.ibatis.datasource.pooled.PooledDataSource -0 [main] WARN org.apache.ibatis.datasource.pooled.PooledDataSource - PooledDataSource forcefully closed/removed all connections.
[service] 2013-04-19 10:30:57,985 - org.apache.ibatis.datasource.pooled.PooledDataSource -3 [main] WARN org.apache.ibatis.datasource.pooled.PooledDataSource - PooledDataSource forcefully closed/removed all connections.
[service] 2013-04-19 10:30:57,986 - org.apache.ibatis.datasource.pooled.PooledDataSource -4 [main] WARN org.apache.ibatis.datasource.pooled.PooledDataSource - PooledDataSource forcefully closed/removed all connections.
[service] 2013-04-19 10:30:57,996 - org.apache.ibatis.datasource.pooled.PooledDataSource -14 [main] WARN org.apache.ibatis.datasource.pooled.PooledDataSource - PooledDataSource forcefully closed/removed all connections.
[service] 2013-04-19 10:30:59,025 - org.apache.ibatis.datasource.pooled.PooledDataSource -1043 [main] WARN org.apache.ibatis.datasource.pooled.PooledDataSource - Created connection 22323092.
[service] 2013-04-19 10:30:59,076 - org.apache.ibatis.datasource.pooled.PooledDataSource -1094 [main] WARN org.apache.ibatis.datasource.pooled.PooledDataSource - Returned connection 22323092 to pool.
很明显,这是显示warn的日志信息了。说明mybatis3只是打印了debug级别的日志。
Java代码
log4j.rootLogger=info, stdout, R
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[service] %d - %c -%-4r [%t] %-5p %c %x - %m%n
log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.File=../logs/service.log
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=[service] %d - %c -%-4r [%t] %-5p %c %x - %m%n
log4j.logger.com.ibatis = debug
log4j.logger.com.ibatis.common.jdbc.SimpleDataSource = debug
log4j.logger.com.ibatis.common.jdbc.ScriptRunner = debug
log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate = debug
log4j.logger.java.sql.Connection = debug
log4j.logger.java.sql.Statement = debug
log4j.logger.java.sql.PreparedStatement = debug
log4j.logger.java.sql.ResultSet =debug
此时,info级别能够输出warn级别的日志,我的日志显示如下:
Java代码
[service] 2013-04-19 10:30:57,982 - org.apache.ibatis.datasource.pooled.PooledDataSource -0 [main] WARN org.apache.ibatis.datasource.pooled.PooledDataSource - PooledDataSource forcefully closed/removed all connections.
[service] 2013-04-19 10:30:57,985 - org.apache.ibatis.datasource.pooled.PooledDataSource -3 [main] WARN org.apache.ibatis.datasource.pooled.PooledDataSource - PooledDataSource forcefully closed/removed all connections.
[service] 2013-04-19 10:30:57,986 - org.apache.ibatis.datasource.pooled.PooledDataSource -4 [main] WARN org.apache.ibatis.datasource.pooled.PooledDataSource - PooledDataSource forcefully closed/removed all connections.
[service] 2013-04-19 10:30:57,996 - org.apache.ibatis.datasource.pooled.PooledDataSource -14 [main] WARN org.apache.ibatis.datasource.pooled.PooledDataSource - PooledDataSource forcefully closed/removed all connections.
[service] 2013-04-19 10:30:59,025 - org.apache.ibatis.datasource.pooled.PooledDataSource -1043 [main] WARN org.apache.ibatis.datasource.pooled.PooledDataSource - Created connection 22323092.
[service] 2013-04-19 10:30:59,076 - org.apache.ibatis.datasource.pooled.PooledDataSource -1094 [main] WARN org.apache.ibatis.datasource.pooled.PooledDataSource - Returned connection 22323092 to pool.
很明显,这是显示warn的日志信息了。说明mybatis3只是打印了debug级别的日志。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询