国产成人精品18p,天天干成人网,无码专区狠狠躁天天躁,美女脱精光隐私扒开免费观看

idea mybatis如何配置log4j打印sql語(yǔ)句

發(fā)布時(shí)間:2021-07-27 11:45 來(lái)源:億速云 閱讀:0 作者:小新 欄目: 編程語(yǔ)言 歡迎投稿:712375056

這篇文章給大家分享的是有關(guān)idea mybatis如何配置log4j打印sql語(yǔ)句的內容。小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過(guò)來(lái)看看吧。

在IDEA中配置log4j,步驟很簡(jiǎn)單

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.編寫(xiě)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>
  <!-- 打印查詢(xún)語(yǔ)句 -->
  <setting name="logImpl" value="LOG4J" />
 </settings>
</configuration>

3.編寫(xiě)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"/>
  <!-- 自動(dòng)掃描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中僅僅單個(gè)Mapper的配置。

<!-- 下面是通過(guò)配置log4j2,僅僅打印出單個(gè)mapper的SQL語(yǔ)句的配置-->
<logger name="com.beebank.dao.iface.UserMapper">
 <level>DEBUG</level>
</logger>

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。

久久综合伊人77777| 一区二区在线 | 欧洲| 无码专区人妻系列日韩精品| 蜜桃网站入口在线进入| 日韩精品免费一线在线观看| 俄罗斯雏妓的BBB孩交|