目录
3.2 编辑核心配置文件(mybatis-config.xml)
1、ORM思想
概括: 利用对象的方式封装数据库
核心规则:
对象与表一一映射.
对象的属性与表中的字段一一映射.
2、 Mybaits框架介绍
小结: Mybatis是一个优秀的持久层框架,基于ORM设计思想,实现了以对象的方式操作数据库.
3 Mybaits使用步骤
3.1 导入jar包
- 课堂使用的是springboot整合mybatis的版本.但是使用其中的依赖包 3.5.7的版本.
- mysql的驱动版本 mysql:mysql-connector-java:8.0.22
- 驱动的配置: com.mysql.cj.jdbc.Driver
- 高版本应该使用高版本数据库
3.2 编辑核心配置文件(applocation.yml)
3.2.1、数据库环境的配置
# 应用服务 WEB 访问端口
server:
port: 8081
#Spring整合数据源 2.mybatis
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/jt?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true
username: root
password: 970824
#SpringBoot整合mybatis
mybatis:
#指定别名包
type-aliases-package: com.jt.pojo
#加载指定的xml映射文件
mapper-locations: classpath:/mybatis/mappers/*.xml
#开启驼峰映射
configuration:
map-underscore-to-camel-case: true
3.2.2、Mapper接口与xml映射文件的绑定关系.
3.3 创建接口/xml映射文件
applocation.yml