SpringMVC+MyBatis+Log4j output sql statement

Today, I want to take a look at the sql statement generated by myBatis to see if there are any syntax errors, but it has not been printed out. Many people have proposed a method for mybatis to output sql statements under springMVC, but I tried it and found that it doesn't work. It is also possible It's a configuration problem for me. Below is my problem, solution, and configuration file.

The problem: the version problem of slf4j and log4j.

Solution: Just replace the mutually supported version in pom.xml, just put a log4j.propertis under src to print out the sql statement.

Configuration file code:

pom.xml:

	<!-- log related -->
		 <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.7</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.7</version>
        </dependency>

 log4j.properties:

log4j.rootLogger=debug, console


log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.Target=System.out
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d %5p %c - %m%n
log4j.logger.java.sql.Connection=debug
log4j.logger.java.sql.Statement=debug
log4j.logger.java.sql.PreparedStatement=debug
log4j.logger.org.mybatis=debug

log4j.logger.org.myrobot.persist=debug
log4j.logger.org.myrobot.dao=debug
log4j.logger.org.myrobot.controller=debug

 org.myrobot.* is my own package, I can test it without adding it. Because log4j.rootLogger has set the global log output method.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326585966&siteId=291194637