1. 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>
<!-- 设置返回HashMap,字段值为null时保存key,如果不设置默认是false -->
<setting name="callSettersOnNulls" value="true" />
</settings>
</configuration>
2. spring-mybatis.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/cn/stock/mapping/*.xml" />
<!-- 配置MyBatis全局配置文件 -->
<property name="configLocation" value="classpath:mybatis-config.xml"></property>
</bean>