日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

zTree菜单的排序

發布時間:2025/3/20 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 zTree菜单的排序 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

zTree菜單的排序,查詢出來為所有的菜單項
循環遍歷取的時候,為了保證它的順序,所以先做個排序
只要保證相同父節點下的,所有的子節點,都是有序的,取的時候,從根節點開始得到的菜單就是有序的

private static List<SystemResource> convertToOrder(List<SystemResource> resources){// ParentId集合,取出所有的parentidList<String> setParentId=new ArrayList<>();for(int i=0;i<resources.size();i++){String ParentId=resources.get(i).getParentId().toString();if(!setParentId.contains(ParentId)){setParentId.add(ParentId);}}// ParentId集合,存放到Map中Map<String, List<SystemResource>> arraySource=new HashMap<String, List<SystemResource>>();for(int i=0;i<setParentId.size();i++){List <SystemResource> systemResourceList=new ArrayList<>();arraySource.put(setParentId.get(i).toString(),systemResourceList);}// 根據Key,添加list,parentid為key,list為所有的子節點for(int i=0;i<resources.size();i++){if(arraySource.containsKey(resources.get(i).getParentId().toString())){arraySource.get(resources.get(i).getParentId().toString()).add(resources.get(i));}}// 根據key,獲取list排序List<SystemResource> resourceList=new ArrayList<>();for(int i=0;i<setParentId.size();i++){List<SystemResource> systemResourceList=new ArrayList<>();if (arraySource.get(setParentId.get(i)).size()>0){systemResourceList=orderSystemResourceList(arraySource.get(setParentId.get(i)));}resourceList.addAll(systemResourceList);}return resourceList; }// list排序,同一個parentID下面的,所有子節點排序 private static List<SystemResource> orderSystemResourceList(List<SystemResource> systemResourceList){// Weight集合,放到Map中,key為子節點的權重,value為子節點Map<String,SystemResource> resourceMap=new HashedMap();for(int i=0;i<systemResourceList.size();i++){SystemResource systemResource=new SystemResource();resourceMap.put(systemResourceList.get(i).getWeight().toString(),systemResourceList.get(i));}// Weight集合,權重集合int arrayInt[]=new int[systemResourceList.size()];for(int i=0;i<systemResourceList.size();i++){arrayInt[i]=systemResourceList.get(i).getWeight();}// Weight集合,權重排序for (int i = 0; i < arrayInt.length; i++) {for (int j = i+1; j < arrayInt.length; j++) {if (arrayInt[i] < arrayInt[j]) {int temp = arrayInt[i];arrayInt[i] = arrayInt[j];arrayInt[j] = temp;}}}// 根據有序的key,獲取value子節點List<SystemResource> systemResourceListByWeight=new ArrayList<>();for (int i=0;i<arrayInt.length;i++){systemResourceListByWeight.add(resourceMap.get(String.valueOf(arrayInt[i])));}return systemResourceListByWeight; }

上述代碼,是用不到的
直接在查詢的時候,排序即可
select * from SYS_RESOURCE ORDER BY PARENT_ID,WEIGHT

總結

以上是生活随笔為你收集整理的zTree菜单的排序的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。