亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

如何實現(xiàn)java遞歸 處理權(quán)限管理菜單樹或分類

 更新時間:2020年01月06日 08:44:11   作者:低調(diào)的小白  
這篇文章主要介紹了如何實現(xiàn)java遞歸 處理權(quán)限管理菜單樹或分類,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下

這篇文章主要介紹了如何實現(xiàn)java遞歸 處理權(quán)限管理菜單樹或分類,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下

1.數(shù)據(jù)庫表設(shè)計

2.實體類設(shè)計

package com.ieou.capsule.dto.SystemPermissions;
import java.util.List;
/**
 * 功能菜單類
 */
public class SystemPermissionsTree {
	private String functionCode;
	//菜單碼
	private String parentFunctionCode;
	//父級菜單碼
	private String functionName;
	//菜單名
	private Boolean flag;
	// true:選中  false:未選中
	private List<SystemPermissionsTree> childrenList;
	public String getFunctionCode() {
		return functionCode;
	}
	public void setFunctionCode(String functionCode) {
		this.functionCode = functionCode;
	}
	public String getParentFunctionCode() {
		return parentFunctionCode;
	}
	public void setParentFunctionCode(String parentFunctionCode) {
		this.parentFunctionCode = parentFunctionCode;
	}
	public String getFunctionName() {
		return functionName;
	}
	public void setFunctionName(String functionName) {
		this.functionName = functionName;
	}
	public Boolean getFlag() {
		return flag;
	}
	public void setFlag(Boolean flag) {
		this.flag = flag;
	}
	public List<SystemPermissionsTree> getChildrenList() {
		return childrenList;
	}
	public void setChildrenList(List<SystemPermissionsTree> childrenList) {
		this.childrenList = childrenList;
	}
}

3.遞歸工具類

package com.ieou.capsule.util;
import com.ieou.capsule.dto.SystemPermissions.SystemPermissionsTree;
import java.util.ArrayList;
import java.util.List;
public class TreeUtil {
	/**
   * 作者:一沐楓一
   * 來源:CSDN
   * 原文:https://blog.csdn.net/gxgl8811/article/details/72803833
   * 版權(quán)聲明:本文為博主原創(chuàng)文章,轉(zhuǎn)載請附上博文鏈接!
   */
	public static List<SystemPermissionsTree> getTreeList(List<SystemPermissionsTree> entityList) {
		List<SystemPermissionsTree> resultList = new ArrayList<>();
		//獲取頂層元素集合
		String parentCode;
		for (SystemPermissionsTree entity : entityList) {
			parentCode = entity.getParentFunctionCode();
			//頂層元素的parentCode==null或者為0
			if (parentCode == null || "0".equals(parentCode)) {
				resultList.add(entity);
			}
		}
		//獲取每個頂層元素的子數(shù)據(jù)集合
		for (SystemPermissionsTree entity : resultList) {
			entity.setChildrenList(getSubList(entity.getFunctionCode(), entityList));
		}
		return resultList;
	}
	/**
   * 獲取子數(shù)據(jù)集合
   *
   * @param id
   * @param entityList
   * @return
   * @author jianda
   * @date 2017年5月29日
   */
	private static List<SystemPermissionsTree> getSubList(String id, List<SystemPermissionsTree> entityList) {
		List<SystemPermissionsTree> childList = new ArrayList<>();
		String parentId;
		//子集的直接子對象
		for (SystemPermissionsTree entity : entityList) {
			parentId = entity.getParentFunctionCode();
			if (id.equals(parentId)) {
				childList.add(entity);
			}
		}
		//子集的間接子對象
		for (SystemPermissionsTree entity : childList) {
			entity.setChildrenList(getSubList(entity.getFunctionCode(), entityList));
		}
		//遞歸退出條件
		if (childList.size() == 0) {
			return null;
		}
		return childList;
	}
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論