|
|
@ -18,7 +18,9 @@ import org.springframework.beans.BeanUtils; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
|
|
|
import java.util.Map; |
|
|
import java.util.Set; |
|
|
import java.util.Set; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
@ -52,15 +54,17 @@ public class SysMenuController extends AbstractController { |
|
|
@GetMapping("/list") |
|
|
@GetMapping("/list") |
|
|
@RequiresPermissions("sys:menu:list") |
|
|
@RequiresPermissions("sys:menu:list") |
|
|
public List<SysMenuEntity> list(){ |
|
|
public List<SysMenuEntity> list(){ |
|
|
// List<SysMenuEntity> menuList = sysMenuService.list(); |
|
|
|
|
|
List<SysMenuEntity> menuList =sysMenuService.lambdaQuery().orderBy(true,true,SysMenuEntity::getOrderNum).list(); |
|
|
|
|
|
for(SysMenuEntity sysMenuEntity : menuList){ |
|
|
|
|
|
SysMenuEntity parentMenuEntity = sysMenuService.getById(sysMenuEntity.getParentId()); |
|
|
|
|
|
if(parentMenuEntity != null){ |
|
|
|
|
|
sysMenuEntity.setParentName(parentMenuEntity.getName()); |
|
|
|
|
|
|
|
|
// 一次查询后在内存中补父级名称,避免N+1数据库访问 - rqrq |
|
|
|
|
|
List<SysMenuEntity> menuList = sysMenuService.lambdaQuery() |
|
|
|
|
|
.orderBy(true, true, SysMenuEntity::getOrderNum) |
|
|
|
|
|
.list(); |
|
|
|
|
|
Map<Long, String> menuNameMap = new HashMap<>(menuList.size()); |
|
|
|
|
|
for (SysMenuEntity menuEntity : menuList) { |
|
|
|
|
|
menuNameMap.put(menuEntity.getMenuId(), menuEntity.getName()); |
|
|
} |
|
|
} |
|
|
|
|
|
for (SysMenuEntity menuEntity : menuList) { |
|
|
|
|
|
menuEntity.setParentName(menuNameMap.get(menuEntity.getParentId())); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return menuList; |
|
|
return menuList; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|