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