首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

递归上拉列表树

2012-11-09 
递归下拉列表树public String add() throws Exception{Property property new Property()property.setD

递归下拉列表树
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("&nbsp;&nbsp;");
}
categoryDto.setName(sb.append(category.getCateName()).toString());
list1.add(categoryDto);
getNewList(category.getCateId(),categoryList,list1,i);
}

}
return list1;
}

热点排行