引入MyBatis依赖
1.使用netbeans创建项目,选择文件->新建项目->Maven->Web应用程序;
2.打开项目目录,在依赖关系上右击->添加依赖关系->查询框输入mysql->选择mysql:mysql-connector-java->点开选择对应的mysql驱动版本.
JDBC链接及操作数据库
3.创建数据库和表
create database foretaste;
use foretaste
create table user_info(id int(11) not null primary key auto_increment,
nickname varchar(50) not null, phone_num char(11) not null,
created_time timestamp not null default current_timestamp,
last_update_time timestamp not null default current_timestamp);
编程式配置方法
4.创建UserInfo的实体
package com.shadow.foretaste.entity;
import java.util.Date;
/**
*
* @author sunny
*/
public class UserInfo {
private int id;
private String nickname;
private String phoneNum;
private Date createdTime;
private Date lastUpdateTime;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
public