Advertisement
KuoHsiangYu

RecipeBean正確寫法

Jul 12th, 2019
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.37 KB | None | 0 0
  1. package com.web.store.model;
  2.  
  3. import java.io.Serializable;
  4. import java.sql.Blob;
  5.  
  6. import javax.persistence.CascadeType;
  7. import javax.persistence.Entity;
  8. import javax.persistence.GeneratedValue;
  9. import javax.persistence.GenerationType;
  10. import javax.persistence.Id;
  11. import javax.persistence.JoinColumn;
  12. import javax.persistence.ManyToOne;
  13. import javax.persistence.Table;
  14. import javax.persistence.Transient;
  15.  
  16. import org.springframework.web.multipart.MultipartFile;
  17.  
  18. //POJO類別
  19. //永續類別都定義在model套件裡面
  20. // 本類別封裝單筆[DB03].[dbo].[recipe]資料
  21. //model裡面的每個class都會對應到資料庫裡的每一張table
  22. //【已完成】1.再加一個欄位設定是否顯示食譜
  23. //【已完成】2.再加一個欄位儲存圖片檔案,這個欄位必須設定成@Transient,因為他只是暫時儲存圖片檔案用的,沒有跟這欄位相對應的資料庫欄位型別。
  24. //【已完成】3.再加一個欄位計算點閱率
  25. //4.還要加一個儲存食材的資料表【】
  26. //【已完成】5.加上FK指向會員編號
  27. //@Transient JPA 使用@Transient來忽略Entity類別屬性映射至資料表
  28. @Entity
  29. @Table(name = "recipe")
  30. public class RecipeBean implements Serializable {
  31.     // TODO 多方,多方對應一方[雙向]。
  32.     // hql語法 只能存取實際類別名稱 RecipeBean 跟 實際屬性名稱 pk_recipe_id。
  33.  
  34.     private static final long serialVersionUID = 1L;
  35.  
  36.     @Id
  37.     @GeneratedValue(strategy = GenerationType.IDENTITY)
  38.     private Integer pk_recipe_id;// 【PK】食譜編號
  39.  
  40. //  private Integer member_id;// 【FK】會員編號//TODO 錯誤寫法1-1
  41.  
  42.     @ManyToOne(cascade = CascadeType.ALL)
  43.     @JoinColumn(name = "fk_member_id")
  44.     private MemberBean memberbean;// TODO 正確寫法,多中有個一。2-1
  45.  
  46.     private String recipe_name;// 食譜名稱
  47.     private String recipe_quantity;// 食譜份量
  48.     private Blob recipe_image;// 食譜圖片
  49.     private String recipe_summary;// 食譜簡介
  50.     private String recipe_time;// 烹調時間
  51.     private String recipe_note;// 小撇步介紹
  52.     private java.sql.Date recipe_date;// 新增食譜時的日期
  53.     private Integer recipe_display;// 設定食譜是否顯示【1正常顯示,公開給大家看。】【2草稿階段尚未發布,只限本人觀看。】【3對所有人隱藏起來】
  54.  
  55.     @Transient
  56.     private MultipartFile image_file;// @Transient_儲存使用者上傳圖片檔案的欄位,之後再轉成 byte[]陣列 塞進 recipe_image。
  57.  
  58.     private String file_name;// 儲存使用者圖片檔案名稱,跟 recipe_image相關。
  59.     private Integer recipe_click_rate;// 計算食譜點閱率
  60.  
  61.     public RecipeBean() {
  62.         // 空的建構子
  63.     }
  64.  
  65.     public Integer getPk_recipe_id() {
  66.         // @GeneratedValue(strategy = GenerationType.SEQUENCE)//不使用,他不會從1開始。
  67.         // GenerationType.IDENTITY PK主鍵編號自動給定,從1開始,每新增一筆資料編號就加1。
  68.         return pk_recipe_id;
  69.     }
  70.  
  71.     public void setPk_recipe_id(Integer pk_recipe_id) {
  72.         this.pk_recipe_id = pk_recipe_id;
  73.     }
  74.  
  75.     public MemberBean getMemberbean() {
  76.         return memberbean;// TODO 正確寫法,多中有個一。2-2
  77.     }
  78.  
  79.     public void setMemberbean(MemberBean memberbean) {
  80.         this.memberbean = memberbean;// TODO 正確寫法,多中有個一。2-3
  81.     }
  82.  
  83. //  @ManyToOne(cascade = CascadeType.ALL)
  84. //  @JoinColumn(name = "fk_member_id")
  85. //  public Integer getMember_id() {
  86. //      return member_id;//TODO 錯誤寫法1-2
  87. //  }
  88. //
  89. //  public void setMember_id(Integer member_id) {
  90. //      this.member_id = member_id;//TODO 錯誤寫法1-3
  91. //  }
  92.  
  93.     public String getRecipe_name() {
  94.         return recipe_name;
  95.     }
  96.  
  97.     public void setRecipe_name(String recipe_name) {
  98.         this.recipe_name = recipe_name;
  99.     }
  100.  
  101.     public String getRecipe_quantity() {
  102.         return recipe_quantity;
  103.     }
  104.  
  105.     public void setRecipe_quantity(String recipe_quantity) {
  106.         this.recipe_quantity = recipe_quantity;
  107.     }
  108.  
  109.     public Blob getRecipe_image() {
  110.         return recipe_image;
  111.     }
  112.  
  113.     public void setRecipe_image(Blob recipe_image) {
  114.         this.recipe_image = recipe_image;
  115.     }
  116.  
  117.     public String getRecipe_summary() {
  118.         return recipe_summary;
  119.     }
  120.  
  121.     public void setRecipe_summary(String recipe_summary) {
  122.         this.recipe_summary = recipe_summary;
  123.     }
  124.  
  125.     public String getRecipe_time() {
  126.         return recipe_time;
  127.     }
  128.  
  129.     public void setRecipe_time(String recipe_time) {
  130.         this.recipe_time = recipe_time;
  131.     }
  132.  
  133.     public String getRecipe_note() {
  134.         return recipe_note;
  135.     }
  136.  
  137.     public void setRecipe_note(String recipe_note) {
  138.         this.recipe_note = recipe_note;
  139.     }
  140.  
  141.     public java.sql.Date getRecipe_date() {
  142.         return recipe_date;
  143.     }
  144.  
  145.     public void setRecipe_date(java.sql.Date recipe_date) {
  146.         this.recipe_date = recipe_date;
  147.     }
  148.  
  149.     public Integer getRecipe_display() {
  150.         return recipe_display;
  151.     }
  152.  
  153.     public void setRecipe_display(Integer recipe_display) {
  154.         this.recipe_display = recipe_display;
  155.     }
  156.  
  157.     public MultipartFile getImage_file() {
  158.         // JPA 使用@Transient來忽略Entity屬性映射至資料表
  159.         return image_file;
  160.     }
  161.  
  162.     public void setImage_file(MultipartFile image_file) {
  163.         this.image_file = image_file;
  164.     }
  165.  
  166.     public String getFile_name() {
  167.         return file_name;
  168.     }
  169.  
  170.     public void setFile_name(String file_name) {
  171.         this.file_name = file_name;
  172.     }
  173.  
  174.     public Integer getRecipe_click_rate() {
  175.         return recipe_click_rate;
  176.     }
  177.  
  178.     public void setRecipe_click_rate(Integer recipe_click_rate) {
  179.         this.recipe_click_rate = recipe_click_rate;
  180.     }
  181.  
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement