好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

springboot实现指定mybatis中mapper文件扫描路径

指定mybatis中mapper文件扫描路径

所有的mapper映射文件

?

1

mybatis.mapper-locations=classpath*:com/springboot/mapper/*.xml

或者resource下的mapper映射文件

?

1

mybatis.mapper-locations=classpath*:mapper/**/*.xml

mybatis配置多个扫描路径写法

百度得到,但是很乱,稍微整理下:

最近拆项目,遇到个小问题,稍微记录下:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

<!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->

     < bean id = "sqlSessionFactory" class = "org.mybatis.spring.SqlSessionFactoryBean" >

         < property name = "dataSource" ref = "dataSource" />

         <!-- 自动扫描mapping.xml文件 -->

         < property name = "mapperLocations" value = "classpath*:com/**/mapping/*.xml" ></ property >

     </ bean >

 

     <!-- DAO接口所在包名,Spring会自动查找其下的类 -->

     < bean class = "org.mybatis.spring.mapper.MapperScannerConfigurer" >

         < property name = "basePackage" value = "com.xxx.dao" />

         <!--<property name="basePackage" value="com.xxx.dao,com.yyyy.dao" />-->

         < property name = "sqlSessionFactoryBeanName" value = "sqlSessionFactory" ></ property >

     </ bean >

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。

原文链接:https://enjoy-day.blog.csdn.net/article/details/105618007

查看更多关于springboot实现指定mybatis中mapper文件扫描路径的详细内容...

  阅读:25次