如何配置mybatis开发环境
1、打开MyEclipse或者Eclipse,新建一个JavaProject项目mybatis
2、下载所需jar包,右键点击项目依次选择New--Folder,此时弹出对话框,Folder name填写lib。复制jar包粘贴到lib文件夹,展开lib文件夹,选中2个jar包,右键点击jar包,依次选择Build Path--Add to Path。
3、打开SQL Server 2008查询分析器,创建mybatis数据库
create database mybatis
选择mybatis数据库,创建users表
create table users(
userId int identity(1,1) primary key,
userName varchar(50) not null,
userPassword char(32) not null,
userBal int default 0
)
4、在mybatis项目下创建cn.hans.mybatis.domain、cn.hans.mybatis.mapper、cn.hans.mybatis.test
5、在cn.hans.mybatis.domain包下创建类User
package cn.hans.mybatis.domain;
public class User {
private Integer userId;
private String userName;
private String userPassword;
// account balance 账户余额
private Integer userBal;
public User(){
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getUserPassword() {
return userPassword;
}
public void setUserPassword(String userPassword) {
this.userPassword = userPassword;
}
public Integer getUserBal() {
return userBal;
}
public void setUserBal(Integer userBal) {
this.userBal = userBal;
}
}