前提你已经配置好了你的Log4j的配置,否则你怎么玩,也不可能在控制台打印日志的。
SpringMVC-servlet.xml
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:mybatis-config.xml"></property>
<!-- 自动扫描mapping.xml文件 -->
<property name="mapperLocations" value="classpath:net/fundway/gzga/mapping/*.xml"></property><!-- mapping文件的路径 -->
</bean>
红色块是我的 映射文件路径
如 userdao.xml的路径
net/fundway/gzga/mapping/*.xml
在此路径下符合此路径的sql语句的xml映射文件
如果你是springboot使用的yml进行配置 ,请无视上面,从下面开始看
application.yml
mybatis:
mapper-locations: classpath*:mybatis-config.xml
mapper-locations: classpath*:/Mapper/*.xml
type-aliases-package: com.demo.Dao
因为是springboot在application.yml中通过上述方式,指定mybatis的一些配置的路径。
application.yml等同于applicationContext.xml
只不过在springboot中简化繁琐的xml配置,所以采用yml格式,更简洁。
当然你同样可用用xml的配置方式。
想了解更多请自行查看springboot官方对yml的配置说明。
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="STDOUT_LOGGING" />
</settings>
</configuration>
参考 http://www.mybatis.org/mybatis-3/zh/configuration.html#settings
楼下发现另外一个方法,在springboot中不使用mybatis-config.xml的方式,没试过了, 你们自己跳过去吧 https://blog.csdn.net/u012666996/article/details/79106599
控制台打印:
==> Preparing: SELECT * FROM t_win WHERE activityId = ? AND batch = ?; ==> Parameters: 37(Integer), 4(Integer)