|
@@ -136,4 +136,35 @@ public class GoodsController {
|
|
|
responseResult.setMessage("获取成功");
|
|
responseResult.setMessage("获取成功");
|
|
|
return JSON.toJSONString(responseResult);
|
|
return JSON.toJSONString(responseResult);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 根据关键字查询京东商品
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequestMapping(value = "/api/getGoodsListByKeyword", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ public String getGoodsListByKeyword(String keywords, int pageNum, int pageSize) {
|
|
|
|
|
+ ResponseResult<List<GoodsBean>> responseResult = new ResponseResult<List<GoodsBean>>();
|
|
|
|
|
+ responseResult.setMessage("获取失败");
|
|
|
|
|
+
|
|
|
|
|
+ // 自带的分页查询
|
|
|
|
|
+ List<GoodsBean> goodsBeanList;
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 如果pageNum为1,pageSize为20,则查询第1*20条到第1*20+20-1(这里的第几条是从0开始的)
|
|
|
|
|
+ goodsBeanList = goodsRepository.getGoodsListByKeyword(keywords, pageNum*pageSize, pageSize);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ return JSON.toJSONString(responseResult);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ responseResult.setContent(goodsBeanList);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ return JSON.toJSONString(responseResult);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ responseResult.setCode(ResultCode.SUCCESS);
|
|
|
|
|
+ responseResult.setMessage("获取成功");
|
|
|
|
|
+ return JSON.toJSONString(responseResult);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|