idea mybatis配置log4j打字与印刷sql语句的演示,mybatislog4j

idea mybatis配置log4j打字与印刷sql语句的示范,mybatislog4j

在IDEA中布局log4j,步骤异常的粗略

1.在Maven中出席以下配置

<dependency>
   <groupId>commons-logging</groupId>
   <artifactId>commons-logging</artifactId>
   <version>1.2</version>
  </dependency>
  <dependency>
   <groupId>log4j</groupId>
   <artifactId>log4j</artifactId>
   <version>1.2.16</version>
  </dependency>

  <dependency>
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-api</artifactId>
   <version>1.5.6</version>
   <type>jar</type>
  </dependency>
  <dependency>
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-simple</artifactId>
   <version>1.5.6</version>
  </dependency>

2.编写mybatis-config.xml文件

<?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" />
 </settings>
</configuration>

3.编写log4j.properties文件

log4j.rootLogger=error, Console 
log4j.logger.com.wocus.wine.dao=debug 
#Console
log4j.appender.Console=org.apache.log4j.ConsoleAppender 
log4j.appender.Console.layout=org.apache.log4j.PatternLayout 
log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n 

4.在扫描mapper的xml文件中

 <!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->
 <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  <property name="dataSource" ref="dataSource"/>
  <!-- 自动扫描mapping.xml文件 -->
  <property name="mapperLocations" value="classpath:com.wocus.wine/dao/*Mapper.xml"/>
  <!-- 配置log4j-->
  <property name="configLocation" value="classpath:mybatis-config.xml"></property>
 </bean>

瞩目:IDEA中的日志输出在output中,如若急需筛选,火速键Ctrl+F

【拓展】

“细粒度”调节:Log4j打字与印刷出MyBatis中可是单个Mapper的安顿。

<!-- 下面是通过配置log4j2,仅仅打印出单个mapper的SQL语句的配置-->
<logger name="com.beebank.dao.iface.UserMapper">
 <level>DEBUG</level>
</logger>

以上正是本文的全体内容,希望对我们的求学抱有协理,也可望我们多多补助帮客之家。

http://www.bkjia.com/Javabc/1301076.htmlwww.bkjia.comtruehttp://www.bkjia.com/Javabc/1301076.htmlTechArticleidea
mybatis配置log4j打字与印刷sql语句的示范,mybatislog4j
在IDEA中布局log4j,步骤很轻松 1.在Maven中投入以下配置 dependency
groupIdcommons-logging/groupId artif…

1.在Maven中参加以下配置

<?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" /> </settings></configuration>

图片 1image.png

<dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.2</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.16</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.5.6</version> <type>jar</type> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId> <version>1.5.6</version> </dependency>

4.在扫描mapper的xml文件中

 <!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 --> <bean > <property name="dataSource" ref="dataSource"/> <!-- 自动扫描mapping.xml文件 --> <property name="mapperLocations" value="classpath:com.wocus.wine/dao/*Mapper.xml"/> <!-- 配置log4j--> <property name="configLocation" value="classpath:mybatis-config.xml"></property> </bean>

3.编写log4j.properties文件

log4j.rootLogger=error, Console log4j.logger.com.wocus.wine.dao=debug #Consolelog4j.appender.Console=org.apache.log4j.ConsoleAppender log4j.appender.Console.layout=org.apache.log4j.PatternLayout log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n 

2.编写mybatis-config.xml文件

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图