为什么springboot项目中没有mybatis-config.xml(Mybatis全局配置文件)

为什么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>
  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值