JavaBean是-一个实体类(存储数据的类)的设计规范!
1、类公开,使用public修饰
2、属性私有化,private修饰
3、为私有属性提供赋值、取值方法
4、必须保证类中存在无参构造方法
示例:
package jdbc_demo;
public class Student {
private int sid;
private String sname;
private String gender;
private String phone;
public int getSid() {
return sid;
}
public void setSid(int sid) {
this.sid = sid;
}
public String getSname() {
return sname;
}
public void setSname(String sname) {
this.sname = sname;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
// 无参构造方法
public Student() {
// TODO Auto-generated constructor stub
}
// 有参构造方法
public Student(int sid, String sname, String gender, String phone) {
super();
this.sid = sid;
this.sname = sname;
this.gender = gender;
this.phone = phone;
}
// 打印对象
@Override
public String toString() {
return "student [sid=" + sid + ", sname=" + sname + ", gender=" + gender + ", phone=" + phone + "]";
}
}