Recursive get the menu bar

@Override 
<?> Public BaseResponse listChildSort () {
// Find all the top-level menu
List <SysPermission> sysPermissionList = sysPermissionMapper.selectByParentId (0);
List <Children> childrenList = Lists.newArrayList ();
for (SysPermission sysPermission: sysPermissionList) {
// add the next menu and the lower menu recursion set
childrenList.add (listChild (sysPermission));
}
IF (childrenList.size () == 0) {
return BaseResponse.createByError ( "no data");
}
BaseResponse.createBySuccess return (childrenList);
}
Private Children listChild (sysPermission sysPermission) {
// recursive new objects
Children Children Children new new = ();
// Name Id and the current menu stored into the object
children.setId (sysPermission.getId () + "");
children.setName (sysPermission.getName ());
menu // Find the previous menu as the current menu ID
List <SysPermission> sysPermissionList = sysPermissionMapper.selectByParentId ( sysPermission.getId ( ) .intValue ());
List <Children> childrenList Lists.newArrayList = ();
// traverse the lower menu
for (SysPermission sysPermissionChild: sysPermissionList) {
// recursive sub-menu, the menu set and stored in the lower
childrenList.add (listChild ( sysPermissionChild));
}
// set the lower menus stored into recursive objects
children.setChildren (childrenList.size ()> 0 childrenList:? null);
return Children;
}

Guess you like

Origin www.cnblogs.com/ONFE/p/12209152.html