商品實體類設計
這裡的商品執行個體也就是書籍。我們會將其構建為一個JavaBean類,以提高代碼的重複利用性和程式的可維護性。這裡有個小技巧用於迅速添加大量的setter和getter:右鍵你的類名,然後在快顯功能表中選擇:”Source” -> “Generate Getters and Setters” -> “Select All” -> “OK”。
package entity;import java.util.Date;public class Book {// 書籍的相關屬性,這裡需要設定為私人許可權 private String isbn; private String name; private String author; private String intro; //書籍簡介 private float price_original; private float price; private String publish_comany; private Date publish_time; private String img_path;// 共有無參建構函式 public Book(){ }// 所有屬性的getter和setter public String getIsbn() { return isbn; } public void setIsbn(String isbn) { this.isbn = isbn; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAuthor() { return author; } public void setAuthor(String author) { this.author = author; } public String getIntro() { return intro; } public void setIntro(String intro) { this.intro = intro; } public float getPrice_original() { return price_original; } public void setPrice_original(float price_original) { this.price_original = price_original; } public float getPrice() { return price; } public void setPrice(float price) { this.price = price; } public String getPublish_comany() { return publish_comany; } public void setPublish_comany(String publish_comany) { this.publish_comany = publish_comany; } public Date getPublish_time() { return publish_time; } public void setPublish_time(Date publish_time) { this.publish_time = publish_time; } public String getImg_path() { return img_path; } public void setImg_path(String img_path) { this.img_path = img_path; }}
你可以在點擊這裡查看更多關於JavaBean的知識。