內建Mybatis的步驟
在SpringBoot中沒有給Mybatis提供一些依賴,但是mybatis自己有對應的springBoot的依賴。
1.首先添加mybatis的依賴
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
2.資料庫驅動程式,在springBoot中引入時,這裡版本是8.0的版本,而8.0的資料庫驅動是必須指明Timezone的。
<!--資料庫驅動-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
3.mybatis的核心配置,在application.yml中如下,這裡簡寫了,映射xml檔案位址和别名的配置
mybatis:
mapper-locations: classpath:mapper/*.xml
type-aliases-package: com.fuke.domain
4.配置mapper接口的掃描 在Application的核心配置類上加上注解@MapperScan(“這裡是mapper接口包”)
5.資料庫連接配接池的配置如下,這裡必須配置timezone時區
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/springboot?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
username: root
password: 123456