Bläddra i källkod

商品返回随机数据

詹子聪 5 år sedan
förälder
incheckning
3582bab426

+ 11 - 2
src/main/java/com/miekir/shibei/controller/api/GoodsController.java

@@ -15,6 +15,7 @@ import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
+import java.util.Random;
 
 @Controller
 public class GoodsController {
@@ -25,6 +26,8 @@ public class GoodsController {
     @Autowired
     private UserRepository userRepository;
 
+    private Random mRandom = new Random();
+
     /**
      * 新增和更新京东商品
      */
@@ -117,11 +120,17 @@ public class GoodsController {
         ResponseResult<List<GoodsBean>> responseResult = new ResponseResult<List<GoodsBean>>();
         responseResult.setMessage("获取失败");
 
-        // 自带的分页查询
+        // 自带的分页查询。这里不使用分页查询,而是返回随机的数据
         List<GoodsBean> goodsBeanList;
+
+        long maxPageNum = goodsRepository.count()/pageSize-1;
+        if (maxPageNum > Integer.MAX_VALUE) {
+            maxPageNum = Integer.MAX_VALUE;
+        }
+        int randomPageNum = mRandom.nextInt((int) maxPageNum);
         try {
             Sort sort = new Sort(Sort.Direction.DESC,"updateTimeMillis");
-            goodsBeanList = goodsRepository.findAll(new PageRequest(pageNum, pageSize, sort)).getContent();
+            goodsBeanList = goodsRepository.findAll(new PageRequest(randomPageNum, pageSize, sort)).getContent();
         } catch (Exception e) {
             e.printStackTrace();
             return JSON.toJSONString(responseResult);

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

@@ -17,7 +17,6 @@ import java.util.Arrays;
 import java.util.concurrent.Executors;
 
 /**
- * todo 真正上线之后就不要启动这个任务了
  * spring mvc web应用启动时就执行特定处理
  *
  */

+ 0 - 1
src/main/java/com/miekir/shibei/tool/web/FileTool.java

@@ -16,7 +16,6 @@ sudo chmod 777 -R /file/images/
 恢复默认权限
 sudo chmod 755 /file/images/*/
 public class FileTool {
-    // todo 客户端使用的时候,记得拼上这个(判断不以http开头的才拼)
     public static final String BASIC_SERVER_URL = "http://jianjie.life/";
 
     // 只要授权之后,是可以直接写这个路径的,但是由于jar包等冲突(或缺失),会导致war包发布的时候,没有真正运行,也就没有文件写进去了。