a.快速构建项目,引入核心maven dependency依赖
<dependency> <groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.6</version>
</dependency>
<!-- 数据库驱动包 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.25</version>
</dependency>
构建POJO类和接口式编程的 Mapper类,编写SQL语句
- package com.mybatis.beans; public class Dept {
- private Integer deptNo; private String dname;
- private String loc;
- public Dept() {}
- public Dept(Integer deptNo, String dname, String loc){
- this.deptNo = deptNo; this.dname = dname; this.loc = loc;
- }
- get and set...
- }
编写config.properties
数据库驱动等配置
构建Mybatis核心配置文件即mybatis-config.xml
,引入数据库驱动,映射Mapper类
编写Junit单元测试类