学习mybatis03---写映射接口与实体类
Posted yangs-blog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了学习mybatis03---写映射接口与实体类相关的知识,希望对你有一定的参考价值。
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;
以上是关于学习mybatis03---写映射接口与实体类的主要内容,如果未能解决你的问题,请参考以下文章
使用mybatis反向自动生成实体类和mapper映射文件和接口文件