递归下拉列表树

public String add() throws Exception
{
Property property = new Property();
property.setDeleteFlag('0');
propertyList = this.getFacadeFactory().getGdsPropertyFacade().findByExample(property);
Category cate = new Category();
cate.setDeleteFlag('0');
List<CategoryDto> list1 = new ArrayList<CategoryDto>();
List<Category> list = this.getFacadeFactory().getGdsCategoryFacade().findByExample(cate);
dtoList = getNewList(new Long(0),list,list1,0);
return SUCCESS;
}
/**
*categoryList 为原先未排序的列表
*list1 排序完后的列表
* i 为递归的次数
*/

private List<CategoryDto> getNewList(Long id, List<Category> categoryList,List<CategoryDto> list1,int i) throws Exception
{
i++;
for(Category category :categoryList)
{
if(category.getParentId().equals(id))
{
CategoryDto categoryDto = new CategoryDto();
categoryDto.setId(category.getCateId());
categoryDto.setParentId(category.getParentId());
StringBuilder sb = new StringBuilder();
for(int j=0;j<i-1;j++) {
sb.append("  ");
}
categoryDto.setName(sb.append(category.getCateName()).toString());
list1.add(categoryDto);
getNewList(category.getCateId(),categoryList,list1,i);
}

}
return list1;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值