@Autowired
private TbItemCatMapper mapper;
@Override
public CatResult getItemCatList() {
// TODO Auto-generated method stub
CatResult catResult = new CatResult();
catResult.setData(getCatList(0));
return catResult;
}
private List<?> getCatList(long parentId){
TbItemCatExample example=new TbItemCatExample();
Criteria criteria = example.createCriteria();
criteria.andParentIdEqualTo(parentId);
List<TbItemCat> list = mapper.selectByExample(example);
List resultList=new ArrayList();
for (TbItemCat tbItemCat : list) {
if(tbItemCat.getIsParent()) {
CatNode catNode = new CatNode();
if(parentId==0) {
catNode.setName("<a href='/products/"+tbItemCat.getId()+".html'>"+tbItemCat.getName()+"</a>");
}else {
catNode.setName(tbItemCat.getName());
}
catNode.setUrl("/products/"+tbItemCat.getId()+".html");
catNode.setItem(getCatList(tbItemCat.getId()));
resultList.add(catNode);
}else {
resultList.add("/products"+tbItemCat.getId()+".html|"+tbItemCat.getId());
}
}
return resultList;
}
查询分类列表的递归调用
猜你喜欢
转载自blog.csdn.net/qq_40967319/article/details/90244548
今日推荐
周排行