Springboot支持快速生成项目,生成前选择项目管理工具,我在此用maven做介绍:
1.生成项目后,将得到的项目文件解压并导入IntelliJ IDEA,在pom.xml文件中配置myBatis,引入如下的依赖:
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.1</version>
</dependency>
在application.properties加入
spring.datasource.url=jdbc:mysql://localhost:3306/mydatabase?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&useSSL=false
配置连接数据库的地址以及数据库名,?符号后面带有一些参数;
mybatis.config-location=classpath:mybatis-config.xml
myBatis的配置路径;
在相同路径中添加maBatis-config.xml,如下图所示:
到这里已经配置完成了,可以写一份sql脚本进行测试;
3.使用测试用例时,在测试代码中通过@Sql注解导入sql脚本;