学习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; } }

 

转载于:https://www.cnblogs.com/yangs-blog/p/11479298.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值