My SQL 中怎么递归查询所有的父节点
1个回答
展开全部
//获取表中所有idprotected List<Long> getIdList(String sql, Object ... params) { return xxx;} //获取该menu下的所有子节点private List<Long> getMenuChildrenIds(long menuId) { String sql = "select menu_id from test_tb where p_id = ? "; return getIdList(sql, menuId);} public void getAllChildren(long menuId, List<Long> menuIdList) { List<Long> childrenIds = getMenuChildrenIds(menuId); for (long menu_Id : childrenIds) { menuIdList.add(menu_Id); //计数 int count = geliDao.count("select count(1) from test_tb where p_id = ? ", menu_Id, status); if (count > 0) { getAllChildren(menu_Id, menuIdList); } }} //public List<Menu> getMenuChildren(long menuId) { return orm.list(Menu.class, getMenuChildrenIds(menuId ).toArray()); } //执行,全找出来menuIds,放到list里面List<Long> menuIds = new ArrayList<Long>();menuIds.add(menu.getMenuId());getAllChildren(menu.getMenuId(), menuIds);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |