Prechádzať zdrojové kódy

爬虫兼数据库插入已就绪

詹子聪 5 rokov pred
rodič
commit
96b728b12f

+ 6 - 5
src/main/java/com/miekir/shibei/bean/db/GoodsBean.java

@@ -1,6 +1,7 @@
 package com.miekir.shibei.bean.db;
 
 import javax.persistence.*;
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -104,14 +105,14 @@ public class GoodsBean {
      */
     @ElementCollection
     @Column(columnDefinition = "MEDIUMTEXT", name = "fanList", nullable = true, insertable = true, updatable = true)
-    public List<String> fanList;
+    public List<String> fanList = new ArrayList<String>();
 
     /**
      * 磁力链接合集
      */
-    @ElementCollection
-    @Column(columnDefinition = "MEDIUMTEXT", name = "magnetBeanList", nullable = true, insertable = true, updatable = true)
-    public List<MagnetBean> magnetBeanList;
+    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
+    @Column(name = "magnetBeanList", nullable = true, insertable = true, updatable = true)
+    public List<MagnetBean> magnetBeanList = new ArrayList<MagnetBean>();
 
     /**
      * 是否已收藏
@@ -125,7 +126,7 @@ public class GoodsBean {
      */
     @ElementCollection
     @Column(columnDefinition = "MEDIUMTEXT", name = "contentImageUrlList", nullable = true, insertable = true, updatable = true)
-    public List<String> contentImageUrlList;
+    public List<String> contentImageUrlList = new ArrayList<String>();
 
     /**
      * 创建时间

+ 12 - 0
src/main/java/com/miekir/shibei/bean/db/MagnetBean.java

@@ -1,5 +1,6 @@
 package com.miekir.shibei.bean.db;
 
+import javax.persistence.*;
 import java.io.Serializable;
 
 /**
@@ -9,7 +10,18 @@ import java.io.Serializable;
  * @date 2020/8/28 16:25
  * Description: 磁力链接
  */
+@Entity
 public class MagnetBean implements Serializable {
+    @Id
+    @GeneratedValue(strategy= GenerationType.AUTO)
+    @Column(name = "id", nullable = false, insertable = true, updatable = false)
+    public long id;
+
+    @Basic
+    @Column(columnDefinition = "MEDIUMTEXT", name = "magnet_text", nullable = true, insertable = false, updatable = false)
     public String text;
+
+    @Basic
+    @Column(columnDefinition = "MEDIUMTEXT", name = "magnet_url", nullable = true, insertable = false, updatable = false)
     public String url;
 }

+ 2 - 1
src/main/java/com/miekir/shibei/tool/web/Sex8Tool.java

@@ -229,7 +229,8 @@ public class Sex8Tool {
                 GoodsBean goodsBean = new GoodsBean();
                 goodsBean.title = title;
                 goodsBean.description = description;
-                goodsBean.magnetBeanList = magnetBeanList;
+                goodsBean.magnetBeanList.addAll(magnetBeanList);
+                goodsBean.contentImageUrlList.addAll(photoList);
 
                 goodsBean.coverImageUrl = photoList.get(0);
                 goodsBean.createTimeMillis = System.currentTimeMillis();