使用spring整合mybatis时映射文件的导入方法主要有两种:
方法1:例如在sqlMapConfig.xml文件中配置:
<mappers>
<mapper resource="com/njupt/pojo/User.xml" />
<mapper resource="com/njupt/pojo/Person.xml" />
<mapper resource="com/njupt/pojo/Order.xml" />
</mappers>
方法2:也可以直接在spring的配置文件中配置:如下所示:
<bean id="sf" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="classpath:sqlMapConfig.xml"/>
<property name="mapperLocations">
<value>classpath:com/njupt/pojo/User.xml</value>
</property>
</bean>

本文介绍在Spring框架下整合MyBatis时如何配置映射文件。主要介绍了两种配置方法:一种是在sqlMapConfig.xml文件中配置;另一种是在Spring配置文件中配置。这些配置确保了MyBatis能够正确读取映射文件。
2365

被折叠的 条评论
为什么被折叠?



