编写 pom 导入依赖
1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 5 <modelVersion>4.0.0</modelVersion> 6 7 <groupId>com.itcast</groupId> 8 <artifactId>day01-mybatis</artifactId> 9 <version>1.0-SNAPSHOT</version> 10 <packaging>jar</packaging> 11 12 <dependencies> 13 <dependency> 14 <groupId>org.mybatis</groupId> 15 <artifactId>mybatis</artifactId> 16 <version>3.5.4</version> 17 </dependency> 18 <dependency> 19 <groupId>mysql</groupId> 20 <artifactId>mysql-connector-java</artifactId> 21 <version>5.1.48</version> 22 </dependency> 23 <dependency> 24 <groupId>log4j</groupId> 25 <artifactId>log4j</artifactId> 26 <version>1.2.17</version> 27 </dependency> 28 <dependency> 29 <groupId>junit</groupId> 30 <artifactId>junit</artifactId> 31 <version>4.10</version> 32 </dependency> 33 </dependencies> 34 </project>
编写User 实体类
先 Getter and Setter() 方法 然后再 toString() 方法
编写持久层接口 UserDao
编写 Config.xml 配置文件
使用注解的方法
编写 Dao 实现类
编写测试类 MybatisTest
测试成功 控制台输出查询的结果 既成功!