Home > Java > javaTutorial > body text

How does springboot specify the mapper file scanning path in mybatis?

WBOY
Release: 2023-05-17 22:25:52
forward
2939 people have browsed it

Specify the mapper file scan path in mybatis

All mapper mapping files

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

or the mapper mapping file under resource

mybatis.mapper-locations=classpath*:mapper/**/*.xml
Copy after login

How to configure multiple scan paths in mybatis

Baidu got it, but it’s very messy. Let’s sort it out a little:

Recently dismantled the project and encountered a small problem. I’ll record it a little bit:

<!-- 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>
Copy after login

The above is the detailed content of How does springboot specify the mapper file scanning path in mybatis?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!