2.5 SpringBoot整合Mybatis
2.5.1 导入jar包
<!--引入数据库驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!--springBoot数据库连接 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!--spring整合mybatis 暂时 -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.4</version>
</dependency>
2.5.2 数据源相关说明
spring:
datasource:
# 自动匹配驱动的版本
url: jdbc:mysql://127.0.0.1:3306/XXXX?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true
username: root
password: root
1.serverTimezone=GMT%2B8& GMT+8
2.useUnicode=true&characterEncoding=utf8 是否使用useUnicode编码,字符的编码格式采用u8格式
3.autoReconnect=true 如果程序链接过程中jdbc链接中断 ,是否重连
4.allowMultiQueries=true 是否允许批量执行
2.5.3 SpringBoot整合Mybatis YML文件
#Mybatis整合
mybatis:
#定义别名包
type-aliases-package: com.jt.pojo
#加载mapper的映射文件
mapper-locations: classpath:/mybatis/mappers/*.xml
#开启驼峰映射
configuration:
map-underscore-to-camel-case: true