1.在src/main/java文件中新建一个包存放mapper接口,包名要符合命名规范
2.新建一个接口,接口名字要语义化,eg:UserMapper
public interface UserMapper { @Select("select * from t_user where id=#{id}") public User findById(int id); @Insert("insert into t_user (name,pwd,birthday,age) values(#{name},#{pwd},#{birthday},#{age})") public int save(User user); @Update("update t_user set name=#{name},pwd=#{pwd},birthday=#{birthday},age=#{age} where id=#{id}") public int update(User user); @Delete("delete from t_user where id=#{id}") public int del(int id); }
3.在src/main/java文件中新建一个包存放实体类,包名要符合命名规范
4.类名为数据库中表名,属性为表的列
public class User { private int id; private String name; private String pwd; private Date birthday; private String age; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPwd() { return pwd; } public void setPwd(String pwd) { this.pwd = pwd; } public Date getBirthday() { return birthday; } public void setBirthday(Date birthday) { this.birthday = birthday; } public String getAge() { return age; } public void setAge(String age) { this.age = age; } public User() { super(); // TODO Auto-generated constructor stub } public User(String name, String pwd, Date birthday, String age) { super(); this.name = name; this.pwd = pwd; this.birthday = birthday; this.age = age; } @Override public String toString() { return "用户id=" + id + ", 用户名=" + name + ", 用户密码=" + pwd + ", 生日=" + birthday + ",
年龄=" + age; } }