java递归读取parent下所有子节点

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/vtopqx/article/details/86234695

Java查询数据库所有数据之后,在程序中递归获取所有parent节点下子节点,

如下代码:

	public static List<Integer> getAllNewsClass(List<Menu> menuList, int pid,List<Integer> childList) {
		for (Menu mu : menuList) {
			//遍历出父id等于参数的id,add进子节点集合
			if (Integer.valueOf(mu.getParentId()) == pid) {
				childList.add(mu.getId());
				//递归遍历下一级
				getAllNewsClass(menuList, mu.getId(),childList);
			}
		}
		return childList;
	}

猜你喜欢

转载自blog.csdn.net/vtopqx/article/details/86234695