1、创建maven工程,导入坐标
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.itcast</groupId>
<artifactId>mybatis_crud</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.5</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.26</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.12</version>
</dependency>
</dependencies>
</project>
2、工程目录
3、数据库表字段
CREATE DATABASE mybatis;
USE DATABASE;
DROP TABLE IF EXISTS student;
CREATE TABLE `student` (
studentNo INT(8) NOT NULL AUTO_INCREMENT COMMENT '学生学号',
studentName VARCHAR(32) NOT NULL COMMENT '学生姓名',
sex CHAR(1) DEFAULT NULL COMMENT '学生性别',
birthday DATETIME DEFAULT NULL COMMENT '学生生日',
PRIMARY KEY(studentNo)
) ENGINE=INNODB DEFAULT CHARSET = utf8;
INSERT INTO student(studentNo,studentName,sex,birthday) VALUES(100,'张三同学','男','2018-02-27 17:47:08');
INSERT INTO student(studentNo,studentName,sex,birthday) VALUES(101,'李四同学','男','2018-02-27 17:47:08');
INSERT INTO student(studentNo,studentName,sex,birthday) VALUES(102,'王五同学','男','2018-02-27 17:47:08');
INSERT INTO student(studentNo,studentName,sex,birthday) VALUES(103,'赵六同学','男','2018-02-27 17:47:08');
4、表对应的实体类
package domain;
import java.io.Serializable;
import java.util.Date;
public class Student implements Serializable {
private Integer studentNo;
private String studentName;
private String sex;
p