搭建MyBatis开发环境和创建Maven工程
2.1、开发环境
- IDE:idea 2019.2
- 构建工具:maven 3.5.4
- MySQL版本:MySQL 8
- MyBatis版本:MyBatis 3.5.7
MySQL不同版本的注意事项
1、驱动类driver-class-name
- MySQL 5版本使用jdbc5驱动,驱动类使用:com.mysql.jdbc.Driver
- MySQL 8版本使用jdbc8驱动,驱动类使用:com.mysql.cj.jdbc.Driver
2、连接地址url
- MySQL 5版本的url: jdbc:mysql://localhost:3306/ssm
- MySQL 8版本的url: jdbc:mysql://localhost:3306/ssm?serverTimezone=UTC
否则运行测试用例报告如下错误:java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized orrepresents more
2.2、创建maven工程
①打包方式:jar
<groupId>com.atguigu.mybatis</groupId>
<artifactId>mybatis_helloworld</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
②引入依赖
<dependencies>
<!-- Mybatis核心 -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.7</version>
</dependency>
<!-- junit测试 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- MySQL驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.16</version>
</dependency>
</dependencies>