Learn MyBatis When you encounter the problem of printing SQL, here is a summary:
1: First log4j.properties such a configuration;
Log4j.rootlogger=Debug,console,rlog4j.appender.console=Org.apache.log4j.ConsoleAppenderlog4j.appender.console.threshold=Debuglog4j.appender.console.layout=Org.apache.log4j.PatternLayoutlog4j.appender.console.layout.ConversionPattern=%d{yyyy-mm-dd HH:MM:SS} [%5p]-%c-%m (%l)-%m%NLOG4J.APPENDER.R=Org.apache.log4j.rollingfileappenderlog4j.appender.r.append=trueLog4j.appender.r.file=d:/Springmvc.loglog4j.appender.r.threshold=Warnlog4j.appender.r.layout=Org.apache.log4j.patternlayoutlog4j.appender.r.layout.conversionpattern=%d{yyyy-mm-dd HH:MM:SS} [%5p]-%c-%m (%l)-%m%nlog4j.appender.r.maxfilesize=20mb# Avoid debug level log input log4j.logger.org= info
2: Check your own imported jar package to see if there are three packages log4j Slf4j-api SLF4J-LOG4J12
If the three packages are present or there is only log4j, skip step 3
3: Project to SLF4J-API and do not want to import slf4j-log12, then make the following configuration:
Spring Configuration:<BeanID= "Sqlsessionfactory"class= "Org.mybatis.spring.SqlSessionFactoryBean"> < Propertyname= "DataSource"ref= "DataSource"/> < Propertyname= "Mapperlocations"value= "Classpath:com/chencheng/mapping/*.xml"/> <!--Register MyBatis Profile--! > <property name= "configlocation" value= "Classpath:mybatis-config.xml"/> &L t;/bean> mybatis-config.xml Configuration <?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= "log4j"/>//Use log4j </settings& Gt;</configuration>
To complete the above configuration, we should be able to see the SQL printed on the console.
MYBATIS3.2.3+SPRING3 Console Print SQL solution