可在 applicationContext-datasource.xml中的sqlSessionFactory中添加mapperLocations属性,扫描mapping目录下的所有xml文件
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:mybatis-configuration.xml"/>
<property name="mapperLocations" value="classpath:/XX/*.xml"/>
</bean>
不用在mybatis-configuration.xml文件中一个个添加xml文件了
<mappers>
<mapper resource="xx/xx.xml"/>
<mapper resource="xx/xx.xml"/>
<mapper resource="xx/xx.xml"/>
<mapper resource="xx/xx.xml"/>
</mappers>