Hibernate创建持久化类

阅读更多
一 JavaBean的四点原则
1.必须是公有的类
2.提供公有的不带参数的默认的构造方法
3.属性私有
4.属性setter/getter封装
 

 

二 创建一个学生持久化类
import java.util.Date;
//学生类
public class Students {
        /*
         * JavaBeans的四点原则
         * 1.必须是公有的类
         * 2.提供公有的不带参数的默认的构造方法
         * 3.属性私有
         * 4.属性setter/getter封装
         */
        private int sid; // 学号
        private String sname; // 姓名
        private String gender; // 性别
        private Date birthday; // 出生日期
        private String address; // 地址
        public Students() {
        }
        public Students(int sid, String sname, String gender, Date birthday,
                        String address) {
                // super();
                this.sid = sid;
                this.sname = sname;
                this.gender = gender;
                this.birthday = birthday;
                this.address = address;
        }
        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 Date getBirthday() {
                return birthday;
        }
        public void setBirthday(Date birthday) {
                this.birthday = birthday;
        }
        public String getAddress() {
                return address;
        }
        public void setAddress(String address) {
                this.address = address;
        }
        @Override
        public String toString() {
                return "Students [sid=" + sid + ", sname=" + sname + ", gender="
                                + gender + ", birthday=" + birthday + ", address=" + address
                                + "]";
        }
}
 

你可能感兴趣的:(Hibernate,持久化类)