数据库中有外键时JavaBean的写法
短信预约 -IT技能 免费直播动态提醒
当写表和实体类之间映射的时候,一旦出现外键,要通过外键找到另外一个类,一旦出现外键必须写成类型
private Address address;
person表
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 +"]";
}
}
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;
}
}
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341