首先最开始我的代码 :
@RequestMapping("/index")
@ResponseBody
public Object index() throws Exception{
PageData pd=this.getPageData();
Map<String,Object> map=new HashMap<String,Object>();
Map<String,Object> data=new HashMap<String,Object>();
//List<PageData> goodsList=new ArrayList<PageData>();
List<PageData> banner=indexService.findBanner(pd);
List<PageData> channel= indexService.findchannel(pd);
List<PageData> newGoodsList= goodsService.findnewgoods(pd);
List<PageData> hotGoodsList= goodsService.findhotgoods(pd);
List<PageData> brandList= goodsService.findbrand(pd);
List<PageData> topicList= topicService.findtopic(pd);
List<PageData> categoryList= categoryService.findCategory(pd);
for(int i=0;i<categoryList.size();i++){
long id= (Long) categoryList.get(i).get("id");
pd.put("id", id);
List<PageData> goodsList= goodsService.findgoodsbyCategory(pd);
//goodsList.addAll(goods);
data.put("goodsList",goodsList);
}
//data.put("goodsList",goodsList);
data.put("categoryList",categoryList);
data.put("topicList",topicList);
data.put("brandList",brandList);
data.put("banner",banner);
data.put("channel", channel);
data.put("newGoodsList",newGoodsList);
data.put("hotGoodsList",hotGoodsList);
map.put("data", data);
map.put("errno", 0);
return map;
}
修改之后:
@RequestMapping("/index")
@ResponseBody
public Object index() throws Exception{
PageData pd=this.getPageData();
Map<String,Object> map=new HashMap<String,Object>();
Map<String,Object> data=new HashMap<String,Object>();
List<PageData> goodsList=new ArrayList<PageData>();
List<PageData> banner=indexService.findBanner(pd);
List<PageData> channel= indexService.findchannel(pd);
List<PageData> newGoodsList= goodsService.findnewgoods(pd);
List<PageData> hotGoodsList= goodsService.findhotgoods(pd);
List<PageData> brandList= goodsService.findbrand(pd);
List<PageData> topicList= topicService.findtopic(pd);
List<PageData> categoryList= categoryService.findCategory(pd);
for(int i=0;i<categoryList.size();i++){
long id= (Long) categoryList.get(i).get("id");
pd.put("id", id);
List<PageData> goods= goodsService.findgoodsbyCategory(pd);
goodsList.addAll(goods);
}
data.put("goodsList",goodsList);
data.put("categoryList",categoryList);
data.put("topicList",topicList);
data.put("brandList",brandList);
data.put("banner",banner);
data.put("channel", channel);
data.put("newGoodsList",newGoodsList);
data.put("hotGoodsList",hotGoodsList);
map.put("data", data);
map.put("errno", 0);
return map;
}
List<PageData> goodsList=new ArrayList<PageData>();
List<PageData> banner=indexService.findBanner(pd);
List<PageData> channel= indexService.findchannel(pd);
List<PageData> newGoodsList= goodsService.findnewgoods(pd);
List<PageData> hotGoodsList= goodsService.findhotgoods(pd);
List<PageData> brandList= goodsService.findbrand(pd);
List<PageData> topicList= topicService.findtopic(pd);
List<PageData> categoryList= categoryService.findCategory(pd);
for(int i=0;i<categoryList.size();i++){
long id= (Long) categoryList.get(i).get("id");
pd.put("id", id);
List<PageData> goods= goodsService.findgoodsbyCategory(pd);
goodsList.addAll(goods);
}
data.put("goodsList",goodsList);
data.put("categoryList",categoryList);
data.put("topicList",topicList);
data.put("brandList",brandList);
data.put("banner",banner);
data.put("channel", channel);
data.put("newGoodsList",newGoodsList);
data.put("hotGoodsList",hotGoodsList);
map.put("data", data);
map.put("errno", 0);
return map;
}
这样添加的数据就不会被覆盖了
欢迎 ⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️⭐️
< END >
程序员NBA
一个有故事的程序员
或者加我微信1414200300一起讨论java技术,有什么问题群里人也可以帮你一起解决