//查询已存的分类值 Listcateids = storeBrandCategoryService.queryStoreCateIds(storeId); //查询分类列表 List cateList = categoryService.queryTopCategory(cate_type); cateLoop(cateList,cateids); //转成josn串 JSONArray arr = JSONArray.fromObject(cateList); String json = arr.toString(); json = json.replaceAll("cate_id", "id").replaceAll("cate_name", "name") .replaceAll("subCategory", "nodes").replaceAll("hasCate", "checked"); mv.addObject("zTreeNodes", json); private void cateLoop(List cateList,List cateids){ if(cateList != null && cateList.size() > 0){ for(Category cate : cateList){ List subCate = categoryService.querysubCategory(cate); cate.setSubCategory(subCate); cate.setHasCate(cateids.contains(cate.getCate_id())); cateLoop(subCate,cateids); } } }
jsp: