Day10-SpringBoot整合mybatis

官方文档 默认你以及引入数据库连接依赖以及配好了数据库 详细可见上篇 点我

1 导入依赖

<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.4</version>
</dependency>

自动整合mybatis依赖

2.配置属性配置文件

# 配置mybatis规则
mybatis:
# config-location: classpath:mybatis/mybatis-config.xml # 指定mybatis全局配置文件 也可直接在yaml里面配置
mapper-locations: classpath:mybatis/mapper/*.xml # Mapper文件位置
configuration:
map-underscore-to-camel-case: true # java驼峰命名法 转数据库下划线风格
  • 导入mybatis官方starter

  • 编写mapper接口。标准@Mapper注解

  • 编写sql映射文件并绑定mapper接口

  • 在application.yaml中指定Mapper配置文件的位置,以及指定全局配置文件的信息 (建议;配置在mybatis.configuration

插件推荐–> IDEA plugins 安装mybatisX