Mybatis中接口和对应的mapper文件位置配置深入剖析
Maven Spring mapper文件路径配置方法
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mybatis="http://mybatis.org/schema/mybatis-spring"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring.xsd">
<!-- 配置接口存储的包,用来扫描mapper接口 -->
<mybatis:scan base-package="edu.zju.bme.data.manage.mapper" />
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 配置mapper文件位置,扫描映射文件,可以使用Ant风格的路径格式 -->
<property name="mapperLocations" value="classpath*:mappers/mapper/*.xml" />
<!-- 指定mybaits与spring结合的配置文件 -->
<property name="configLocation" value="classpath:mybatis/sqlMapcfg.xml" />
// ...
</bean>
</beans>
至于接口的话,则是如下配置
<!-- 指定dao接口地址即注入seqSessionFactory -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.qufenqi.pay.channel.dao" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
</bean>
网友评论