mybatis print sql log

   Most of the configurations on the Internet are in this format.

  

###Show SQL statement part
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

But I tried for a long time without success,

And some online added

log4j.rootLogger=DEBUG, stdout

In fact, if you add this sentence, you don't need to add those configurations of mybatis, and the log can be printed, but there will be many useless logs or logs that we don't care about.

Finally, there are two ways to achieve mybatis printing sql.

1. The settings that come with mybatis

<settings>  
       <setting name="logImpl" value="STDOUT_LOGGING" />  
  </settings>

Just add this sentence to mybatis-config.xmi; (the labels under configuration are in order, otherwise an error will be reported: properties?, settings?, typeAliases?, typeHandlers?, objectFactory?,
 objectWrapperFactory?, reflectorFactory?, plugins ?, environments?, databaseIdProvider?, mappers?)

2. Using LOG4J

in log4j.properties

log4j.logger.com.demo.mapper = DEBUG

In fact, as long as your dao layer, that is, mapper's interface layer log level, is set to DEBUG;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325056808&siteId=291194637