JDBC基础学习笔记_05_jdbc的程序优化_DTC相关

时间:2022-09-12 22:48:29

一.我们新建一个类,到一个新建包

package com.langzimingjian.entity;

/**
* 因為每一個表都會有一個主鍵,這個idEntity封裝了這個主鍵
* @author 13641
*
*/
public abstract class idEntity {
protected long id;

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

}
二. 新建一个用户类

package com.langzimingjian.entity;



public class User extends IdEntity {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
private String password;
private String email;


@Override
public String toString() {
return "User [name=" + name + ", password=" + password + ", email="
+ email + ", id=" + id + "]";
}


}
这样用户类编写完毕。


二.我们新建一个类,存address

package com.langzimingjian.entity;

public class Address extends IdEntity{
private String city;
private String country;
private String userId;
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
@Override
public String toString() {
return "Address [city=" + city + ", country=" + country + ", userId="
+ userId + ", id=" + id + "]";
}


}