为什么springboot项目中没有mybatis-config.xml(Mybatis全局配置文件)?
因为Springboot整合了Mybatis,mybatis-config.xml可以省略不写,在application.yml中进行配置就可以了。

#mybaitis配置
mybatis:
  type-aliases-package: com.yang.springcloud.pojo
  #可以不配置
  #config-location: classpath:mybatis/mybatis-config.xml
  mapper-locations: classpath:mybatis/mapper/*.xml
  #mybatis缓存
  configuration:
    cache-enabled: true

  #Spring的配置
spring:
  application:
    name: xxxx
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: org.gjt.mm.mysql.Driver
    url: jdbc:mysql://localhost:3306/db01?useUnicode=true&characterEncoding=utf-8
    username:root
    password: xxxxxx

正常mybatis-config.xml写法,因为springboot整合mybatis内容都可以省略,所以该文件可以不用创建

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <!-- 使用spring整合mybatis时,以下代码可以省略-->
    <environments default="……">
        <environment id="……">
            <transactionManager type="JDBC" />
            <dataSource type="POOLED">
                <property name="driver" value="com.mysql.jdbc.Driver" />
                <property name="url" value="jdbc:mysql://localhost/mybatis" />
                <property name="username" value="root" />
                <property name="password" value="" />
            </dataSource>
        </environment>
    </environments>

    <!-- 使用spring整合mybatis时,以下代码也可以省略-->
    <mappers>
        <mapper resource="com/njupt/pojo/User.xml" />
        <mapper resource="com/njupt/pojo/Person.xml" />
        <mapper resource="com/njupt/pojo/Order.xml" />
    </mappers>
<!--Springboot整合了mybatis,其实该文件可以不写,直接在application.yml中把该配置的配置了就可以-->
</configuration>
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐