=======================打印sql log4j配置=====================
# Rules reminder:
# DEBUG < INFO < WARN < ERROR < FATAL
# Global logging configuration
# My logging configuration...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
#log4j.appender.stdout.layout.ConversionPattern=%5p %d %C: %m%n
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
#mybatis logger config
log4j.logger.com.ibatis=DEBUG
log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=info
log4j.logger.org.apache.ibatis.jdbc.ScriptRunner=info
log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=info
log4j.logger.java.sql.ResultSet=info
log4j.logger.java.sql.Connection=info
log4j.logger.java.sql.Statement=info
log4j.logger.java.sql.PreparedStatement=info
log4j.rootLogger=DEBUG,stdout
jar包如下:
log4j-1.2.17.jar
mybatis-3.2.3.jar
mysql-connector-java-5.0.4-bin.jar
===========================打印sql log4j配置结束=======================
hibernate和myibatis3在代码上的区别:
hibernate的UserDao必须实现UserDaoImpl,然后写java代码。
myIbatis是面向接口编程的不需要实现UserDaoImpl,只需配置mapper.xml文件中相应的sql即可。
但是需要在spring的配置文件中加入:
<!-- scan for mappers and let them be autowired -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.mybatis.dao" />
</bean>