81,122
社区成员




//获取表中所有id
protected 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);
大概就是这么个意思了,我也胡乱贴上去的,希望对你有帮助
select ... select ...start with ... connect by prior ...
在mysql中里面没有这么便利的内置函数,要么你写存储过程或者函数,要么在自己在java代码端写递归函数,通常是写递归函数的,dba不会随便让你乱改数据库的