A.步骤
- 自定义接口IUserDao
- 定义IUserDao.xml
- 将IUserDao接口和IUserDao.xml放到IUserDao接口的包下
- 将MapperFactoryBean注入到spring容器,设置参数mapperInterface,sqlSessionFactory, 会将映射文件加载到spring中
- 将sqlSessinFactory注入到spring容器.设置参数configLocation,dataSource
- 将dataSource注入到spring容器,设置参数driverClass,jdbcUrl,user,password
B.代码实现
<bean class="org.mybatis.spring.mapper.MapperFactoryBean">
<property name="mapperInterface" value="com.qzw.dao.IUserDao"></property>
<property name="sqlSessionFactory" ref="sqlSessionFactory"></property>
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!‐‐<property