Java 簡單類和資料的對映

2021-07-30 04:06:42 字數 2374 閱讀 9738

#此**包含

1.一對一的對映

2.一對多的對映

3.多對多的對映

package yingshe;

public class book

public void setowners(owners owners)

public book getbooks()

public void setbooks(book books)

public owners getowner()

public void setowner(owners owner)

public book(string bookid,string bookname,string bookauthor,double bookprice,string bookpress,string bookkind)

public string getbookid()

public void setbookid(string bookid)

public string getbookname()

public void setbookname(string bookname)

public string getbookauthor()

public void setbookauthor(string bookauthor)

public double getbookprice()

public void setbookprice(double bookprice)

public string getbookpress()

public void setbookpress(string bookpress)

public string getbookkind()

public void setbookkind(string bookkind)

public string getinfo()

}package yingshe;

public class owners

public void setowners(owners owners)

public book getbooks()

public void setbooks(book books)

public owners(string ownername,string ownerid)

public string getownername()

public void setownername(string ownername)

public string getownerid()

public void setownerid(string ownerid)

public book getbook()

public void setbook(book book)

public string getinfo()

}package yingshe;

public class bookdemo

public static void main(string args)

public void yiduiyi()

public void yiduiduo(); //某人可能擁有這批書

owners owners=new owners("王源", "9527");

owners.setbooks(books);

//設定三本書擁有者

book.setowner(owners);

book1.setowner(owners);

book2.setowner(owners);

system.out.println("通過擁有者找出他所擁有的書:");

for(int i=0;i

一對一的對映結果:

一對多的對映結果:

多對多的對映結果:

資料表與簡單java類對映 角色許可權

先上模板 class dept public string getinfo class emp public string getinfo class role public string getinfo class action public string getinfo 再上 class dep...

Java類和陣列(練習)

一道練習題,所牽扯出來非知識點本身的內容 一道入門級練習題 1.定義類student,包含三個屬性 學號number int 年級state int 成績score int 2.建立20個學生物件,學號為1到20,年級和成績都由隨機數確定,列印出3年級 state值為3 的學生資訊 public c...

Java列舉類的簡單使用

列舉類的本質就是提供有限個例項,我們自己不能隨便new物件,那麼我們先按照如下步驟自己手動實現一下代表季節的列舉類,提供春 夏 秋 冬4個例項 定義myenumation類,私有化建構函式 宣告季節名稱 季節描述2個成員變數,生成相應的構造方法和set get方法 宣告4個靜態的myenumatio...