1、log4j配置
log4jloggercomibatis=DEBUGlog4jloggercomibatiscommonjdbcSimpleDataSource=DEBUG
log4jloggercomibatiscommonjdbcScriptRunner=DEBUG
log4jloggercomibatissqlmapengineimplSqlMapClientDelegate=DEBUG
log4jloggerorgmybatis=DEBUG
log4jloggerjavasqlConnection=DEBUG
log4jloggerjavasqlStatement=DEBUG
log4jloggerjavasqlPreparedStatement=DEBUG
log4jloggerjavasqlResultSet=DEBUG
2、导入jar
<dependency><groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1214</version>
</dependency>
<dependency>
<groupId>orgslf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>177</version>
</dependency>
<dependency>
<groupId>orgslf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>177</version>
</dependency>
3、注意一定要导入slf4j的包,否则sql语句打印不出来
Update your sessionFactory as follows:<bean id="sessionFactory" class="orgspringframeworkormhibernate4LocalSessionFactoryBean">
<property name="dataSource" ref="jndiDataSource" />
<property name="packagesToScan" value="comexampleabc"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernateshow_sql">true</prop>
</props>
</property>
</bean>thinkphp如何打印sql语句
thinkphp如何打印sql语句?比如 $member = M("member"); $map['id'] = 1; $result = $member->where($map)->delete();
SQL语句应该是delete from table member where id = 1;
怎样输出这个sql判断?我记得有个函数,但忘了是哪个了
------解决方法--------------------
getLastSql
------解决方法--------------------
echo M("member")->getLastSql();MyBatis自己内部使用的是Log4j,但实际上支持用户使用各种Log技术。如果配置正确的话,也就是启用debug级别即可打印所有的MyBatis的语句。比如,在我的web程序中,使用logback,maven依赖如下:orgslf4jjcl-over-slf4j161runtimechqos
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)