List内容分组去重

版权声明:如需转载,请务必通知! https://blog.csdn.net/qq_39594542/article/details/85243580

分组查询

${temp.proname} ${temp.leix} ${temp.pingpai} ${temp.jiage}

@RequestMapping(“selectCode”)
public String selectCode(Model model){
//set是可以去重的所以放置set中
Set setLeix = new HashSet();
Set setPingpai = new HashSet();
for(int i = 0 ; i<list.size();i++){
setLeix.add(list.get(i).getLeix());
setPingpai.add(list.get(i).getPingpai());
}
//定义一个List用来接收 待会儿传到前台让他重新展示一下
List listAll = new ArrayList<>();
//先按照类型循环
for(String str:setLeix){
List liType = new ArrayList<>();
for(int i = 0;i<list.size();i++){
ProductClass productClass = list.get(i);
if(str.equals(productClass.getLeix())){
liType.add(productClass);
}
}
//根据对应的类型进行品牌分组
for (String from:setPingpai){
for (int i = 0; i <liType.size(); i++) {
ProductClass pl = liType.get(i);
if (from.equals(pl.getPingpai())){
listAll.add(pl);
}
}
}
}

model.addAttribute(“productlist”,listAll);
return “productlist”;
}

猜你喜欢

转载自blog.csdn.net/qq_39594542/article/details/85243580