private List<?> getList(long parentId) {
//创建查询条件
TbItemCatExample example = new TbItemCatExample();
Criteria criteria = example.createCriteria();
criteria.andParentIdEqualTo(parentId);
List<TbItemCat> list = itemCatMapper.selectByExample(example);
List resultList = new ArrayList<>();
//循环计数
int count = 0;
for (TbItemCat tbItemCat : list) {
//如果为父节点
if (tbItemCat.getIsParent()) {
ItemCatNode node = new ItemCatNode();
node.setUrl("/products/" + tbItemCat.getId() + ".html");
//判断是否为第一层节点
if (parentId == 0) {
node.setName("<a href='"+node.getUrl()+"'>"+tbItemCat.getName()+"</a>");
} else {
node.setName(tbItemCat.getName());
}
node.setItems(getList(tbItemCat.getId()));
resultList.add(node);
} else {
String node = "/products/"+tbItemCat.getId()+".html|" + tbItemCat.getName();
resultList.add(node);
}
count++;
//第一个层循环,只取14条记录
if (parentId == 0 && count >= 14) {
break;
}
}
return resultList;
}