数据库中有外键时JavaBean的写法-成都快上网建站

数据库中有外键时JavaBean的写法

当写表和实体类之间映射的时候,一旦出现外键,要通过外键找到另外一个类,一旦出现外键必须写成类型
private Address address;
person表

创新互联是一家专注于网站设计制作、成都网站建设与策划设计,鄂伦春网站建设哪家好?创新互联做网站,专注于网站建设10多年,网设计领域的专业建站公司;建站业务涵盖:鄂伦春等地区。鄂伦春做网站价格咨询:18982081108

public class Person {
    private String pid;
    private String pname;
    private int age;

    private Address address;

    public Address getAddress() {
        return address;
    }
    public void setAddress(Address address) {
        this.address = address;
    }
    public String getPid() {
        return pid;
    }
    public void setPid(String pid) {
        this.pid = pid;
    }
    public String getPname() {
        return pname;
    }
    public void setPname(String pname) {
        this.pname = pname;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    //覆盖原来的toString方法
    @Override
    public String toString() {
        return "Person [pid=" + pid + ",pname=" + pname + ",age=" + age +"]";
    }
}

数据库中有外键时JavaBean的写法

public class Address {
    private String aid; //主键
    private String province; //省
    private String city; //市
    private String district; //区
    private String street; //街道

    public String getAid() {
        return aid;
    }
    public void setAid(String aid) {
        this.aid = aid;
    }
    public String getProvince() {
        return province;
    }
    public void setProvince(String province) {
        this.province = province;
    }
    public String getCity() {
        return city;
    }
    public void setCity(String city) {
        this.city = city;
    }
    public String getDistrict() {
        return district;
    }
    public void setDistrict(String district) {
        this.district = district;
    }
    public String getStreet() {
        return street;
    }
    public void setStreet(String street) {
        this.street = street;
    }
}

当前文章:数据库中有外键时JavaBean的写法
网址分享:http://kswjz.com/article/jpjdgs.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流