62,634
社区成员




package beantest.bean;
/**
*冰箱
*
*/
public class Fridge {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
/**
* 冰箱具有打开的行为
*/
public void open(){
System.out.println("打开"+name);
}
/**
* 冰箱具有关闭的行为
*/
public void close(){
System.out.println("关闭"+name);
}
}
package beantest.bean;
/**
*爱好
*
*/
public class Hobby {
/**
* 主键--在数据库中的下标
*/
private int id;
/**
* 名称
*/
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Hobby(int id, String name) {
super();
this.id = id;
this.name = name;
}
@Override
public String toString() {
return "Hobby [id=" + id + ", name=" + name + "]";
}
}
package beantest.bean;
/**
* 职业
*/
public class Job {
/**
* 主键--在数据库中的下标
*/
private int id;
/**
* 名称
*/
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Job(int id, String name) {
super();
this.id = id;
this.name = name;
}
public Job() {
super();
}
@Override
public String toString() {
return "Job [id=" + id + ", name=" + name + "]";
}
}
package beantest.bean;
import java.util.List;
/**
* 人
*/
public class Person {
/**
* 主键--在数据库中的下标
*/
private int id;
/**
* 姓名
*/
private String name;
/**
* 性别 1-男 2-女
*/
private int male;
/**
* 年龄
*/
private int age;
/**
* 是否在世
*/
private boolean isLive;
/**
* 父亲id引用 -1表示不存在
*/
private int fatherId;
/**
* 母亲id引用 -1表示不存在
*/
private int motherId;
/**
* 爱人的id引用 -1表示不存在
*/
private int loverId;
/**
* 职业的id引用 -1表示不存在
*/
private int jobId;
/**
* 由于可以有多个爱好,所以一个人拥有爱好ID的集合
*/
private List<Integer> hobbyList;
public List<Integer> getHobbyList() {
return hobbyList;
}
public void setHobbyList(List<Integer> hobbyList) {
this.hobbyList = hobbyList;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getMale() {
return male;
}
public void setMale(int male) {
this.male = male;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public boolean isLive() {
return isLive;
}
public void setLive(boolean isLive) {
this.isLive = isLive;
}
public int getFatherId() {
return fatherId;
}
public void setFatherId(int fatherId) {
this.fatherId = fatherId;
}
public int getMotherId() {
return motherId;
}
public void setMotherId(int motherId) {
this.motherId = motherId;
}
public int getLoverId() {
return loverId;
}
public void setLoverId(int loverId) {
this.loverId = loverId;
}
public int getJobId() {
return jobId;
}
public void setJobId(int jobId) {
this.jobId = jobId;
}
public Person() {
super();
}
public Person(int id, String name, int male, int age, boolean isLive,
int fatherId, int motherId, int loverId, int jobId) {
super();
this.id = id;
this.name = name;
this.male = male;
this.age = age;
this.isLive = isLive;
this.fatherId = fatherId;
this.motherId = motherId;
this.loverId = loverId;
this.jobId = jobId;
}
@Override
public String toString() {
return "Person [id=" + id + ", name=" + name + ", male=" + male + ", age="
+ age + ", isLive=" + isLive + ", fatherId=" + fatherId
+ ", motherId=" + motherId + ", loverId=" + loverId + ", jobId="
+ jobId + "]";
}
}
package beantest.dao;
import java.util.List;
/**
*单表 CRUD的类
*/
public class BaseDao<T> {
/**
* 操作哪个表
*/
private List<T> table;
public BaseDao(List<T> table) {
super();
this.table = table;
}
/**
* 插入
*/
public void insert(T t){
table.add(t);
}
/**
* 查询
*/
public T query(int id){
return table.get(id);
}
/**
* 修改
*/
public void update(T t,int id){
table.set(id, t);
}
/**
* 删除
*/
public T delete(int id){
return table.remove(id);
}
}
package beantest.db;
import java.util.ArrayList;
import java.util.List;
import beantest.bean.Hobby;
import beantest.bean.Job;
import beantest.bean.Person;
import beantest.util.Dectionary;
/**
*数据库,每个数据库的记录的id从0开始
*
*/
public class DataBase {
public static List<Person> personDb=new ArrayList<Person>();
public static List<Job> jobDb=new ArrayList<Job>();
public static List<Hobby> hobbyDb=new ArrayList<Hobby>();
//初始化数据库并设置关联
static{
//初始化person数据库
Person p0=new Person(0, "老王的父亲", Dectionary.Male, 60, Dectionary.Live, -1, -1, 1,-1);
Person p1=new Person(1, "老王的母亲", Dectionary.Female, 60, Dectionary.Live, -1, -1, 0,-1);
Person p2=new Person(2, "老李的父亲", Dectionary.Male, 60, Dectionary.Live, -1, -1, 3,-1);
Person p3=new Person(3, "老李的父亲", Dectionary.Female, 60, Dectionary.Live, -1, -1, 2,-1);
Person p4=new Person(4, "老王", Dectionary.Male, 40, Dectionary.Live, 0, 1, 5,0);
Person p5=new Person(5, "老李", Dectionary.Female, 40, Dectionary.Live, 2, 3, 4,1);
Person p6=new Person(6, "儿子", Dectionary.Male, 15, Dectionary.Live, 4, 5, -1, 2);
personDb.add(p0); personDb.add(p1); personDb.add(p2); personDb.add(p3);
personDb.add(p4); personDb.add(p5); personDb.add(p6);
//初始化job数据库
Job job0=new Job(0, "教师");
Job job1=new Job(1, "会计");
Job job2=new Job(2, "上中学");
jobDb.add(job0);jobDb.add(job1);jobDb.add(job2);
//初始化hobby数据库
Hobby h0=new Hobby(0, "太极拳");
Hobby h1=new Hobby(0, "兼职讲课");
hobbyDb.add(h0);
hobbyDb.add(h1);
//设置爱好
List<Integer> wangList=new ArrayList<Integer>();
List<Integer> liList=new ArrayList<Integer>();
wangList.add(0);
liList.add(1);
p0.setHobbyList(wangList);
p1.setHobbyList(liList);
}
}
public Hobby(int id, String name) {
super();
this.id = id;
this.name = name;
}