Przeglądaj źródła

查询商品接口

詹子聪 5 lat temu
rodzic
commit
e131fa9ce8

+ 12 - 4
src/main/java/com/miekir/shibei/bean/db/GoodsBean.java

@@ -1,8 +1,13 @@
 package com.miekir.shibei.bean.db;
 
+import org.hibernate.annotations.LazyCollection;
+import org.hibernate.annotations.LazyCollectionOption;
+
 import javax.persistence.*;
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 /**
  *
@@ -104,8 +109,9 @@ public class GoodsBean {
      * 烦号信息
      */
     @ElementCollection
+    @LazyCollection(LazyCollectionOption.FALSE)
     @Column(columnDefinition = "MEDIUMTEXT", name = "fanList", nullable = true, insertable = true, updatable = true)
-    public List<String> fanList = new ArrayList<String>();
+    public Set<String> fanList = new HashSet<String>();
 
     /**
      * 磁力链接合集
@@ -113,7 +119,7 @@ public class GoodsBean {
     //@Column(name = "magnetBeanList", nullable = true, insertable = true, updatable = true)
     //对应的是MagnetBean里的变量名goodsBean
     @OneToMany(mappedBy="goodsBean", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
-    public List<MagnetBean> magnetBeanList = new ArrayList<MagnetBean>();
+    public Set<MagnetBean> magnetBeanList = new HashSet<MagnetBean>();
 
     /**
      * 是否已收藏
@@ -124,10 +130,12 @@ public class GoodsBean {
 
     /**
      * 内容的图片链接列表
+     * 需要增加@LazyCollection(LazyCollectionOption.FALSE),否则会报no session or session was closed错误
      */
     @ElementCollection
+    @LazyCollection(LazyCollectionOption.FALSE)
     @Column(columnDefinition = "MEDIUMTEXT", name = "contentImageUrlList", nullable = true, insertable = true, updatable = true)
-    public List<String> contentImageUrlList = new ArrayList<String>();
+    public Set<String> contentImageUrlList = new HashSet<String>();
 
     /**
      * 创建时间
@@ -152,7 +160,7 @@ public class GoodsBean {
      */
     @Basic
     @Column(name = "seeNum", nullable = true, insertable = true, updatable = true)
-    public long seeNum;
+    public Long seeNum;
 
     /**是否是本地写死的数据*/
     @Basic

+ 2 - 2
src/main/java/com/miekir/shibei/controller/task/CrawlerService.java

@@ -34,7 +34,7 @@ public class CrawlerService {
     public void init() {
         // 调试的时候会执行两次,真正部署时其实是执行一次
         // 一启动完成就开始去爬虫
-        Executors.newSingleThreadExecutor().submit(new Runnable() {
+        /*Executors.newSingleThreadExecutor().submit(new Runnable() {
             @Override
             public void run() {
                 // 递归会导致StackOverflowError,所以用循环代替
@@ -43,6 +43,6 @@ public class CrawlerService {
                     shouldContinue = Sex8Tool.startGettingData(CrawlerService.this);
                 }
             }
-        });
+        });*/
     }
 }

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

@@ -28,8 +28,8 @@ public class Sex8Tool {
     }
 
     private static boolean mIsLoading;
-    // 从第二页开始爬
-    private static int mCurrentPage = 150;
+    // todo 每天爬取第二页前面5条
+    private static int mCurrentPage = 50;
 
     /**
      * 为了防止被百度拦截(人机识别),需要按F12查看浏览器的Header,设置相关属性