springboot整合mybatis时候的配置文件需要进行注意的地方

其次在application.properties文件中配置mybatis的mapper文件位置,和实体类的包路径,还有最好加上驼峰命名规范

####mybatis配置
# 注意注意
mybatis.mapper-locations=classpath:edu/hohai/chapter1/gt/mapper/*.xml
#mybatis.mapper-locations=classpath:mapper/*.xml   #这种方式需要自己在resources目录下创建mapper目录然后存放xml
mybatis.type-aliases-package=edu.hohai.chapter1.gt.entity
# 驼峰命名规范 如:数据库字段是  order_id 那么 实体字段就要写成 orderId
mybatis.configuration.map-underscore-to-camel-case=true

看下项目结构:这里我把Mapper类和Mapper映射文件放在了一起,这时候我们还需要做下面设置,让springboot能在java包中扫描xml文件(springboot默认扫描的是包中的*.java文件),如果使用resources目录下面的xml,这打开上面的

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

 设置springboot在包中扫描xml文件

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <fork>true</fork>
                </configuration>
            </plugin>
        </plugins>
 
        <!--下面主要是设置在java包里面也让springboot扫描xml类型的配置文件-->
        <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
                <filtering>true</filtering>
            </resource>
        </resources>
</build>

猜你喜欢

转载自www.cnblogs.com/qingmuchuanqi48/p/12231560.html