# SystemMenu
**Repository Path**: nozero/SystemMenu
## Basic Information
- **Project Name**: SystemMenu
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 1
- **Forks**: 0
- **Created**: 2021-05-19
- **Last Updated**: 2021-11-21
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# ASP.NET CORE WebApi接口示例
> 创建ASP.NET CORE API项目数据库访问自行百度,数据库结构参考文档就行,结构都类似,
>数据对象如下:
```C#
///
/// 菜单表
///
[Table("bee_system_menu")]
public class SystemMenuEntity
{
///
/// ID
///
[Key]
[Required]
public long id { get; set; }
///
/// 父级ID
///
[Required]
public long pid { get; set; }
///
/// 名称
///
[Required]
public string title { get; set; }
///
/// 菜单图标
///
public string icon { get; set; }
///
/// 链接
///
public string href { get; set; }
///
/// 链接
///
public string target { get; set; }
///
/// 序号
///
public int sort { get; set; }
///
/// 是否菜单
///
public bool status { get; set; }
}
```
```C#
///
/// 菜单结果对象
///
public class MenusInfoResultDTO
{
///
/// 权限菜单树
///
public List MenuInfo { get; set; }
///
/// logo
///
public LogoInfo LogoInfo { get; set; }
///
/// Home
///
public HomeInfo HomeInfo { get; set; }
}
public class LogoInfo
{
public string title { get; set; } = "sdsdsdsff";
public string image { get; set; } = "images/logo.png";
public string href { get; set; } = "";
}
public class HomeInfo
{
public string title { get; set; } = "首页";
public string href { get; set; } = "page/welcome-1.html?t=1";
}
///
/// 树结构对象
///
public class SystemMenu
{
///
/// 数据ID
///
public long Id { get; set; }
///
/// 父级ID
///
public long PId { get; set; }
///
/// 节点名称
///
public string Title { get; set; }
///
/// 节点地址
///
public string Href { get; set; }
///
/// 新开Tab方式
///
public string Target { get; set; } = "_self";
///
/// 菜单图标样式
///
public string Icon { get; set; }
///
/// 排序
///
public int Sort { get; set; }
///
/// 子集
///
public List Child { get; set; }
}
```
> 创建一个根对象来接受处理好的数据
```C#
SystemMenu rootNode = new SystemMenu()
{
Id = 0,
Icon = "",
Href = "",
Title = "根目录",
};
```
> 递归处理数据库返回的数据方法参考如下,
```C#
///
/// 递归处理数据
///
///
///
public static void GetTreeNodeListByNoLockedDTOArray(SystemMenuEntity[] systemMenuEntities, SystemMenu rootNode)
{
if (systemMenuEntities == null || systemMenuEntities.Count() <= 0)
{
return;
}
var childreDataList = systemMenuEntities.Where(p => p.pid == rootNode.Id);
if (childreDataList != null && childreDataList.Count() > 0)
{
rootNode.Child = new List();
foreach (var item in childreDataList)
{
SystemMenu treeNode = new SystemMenu()
{
Id = item.id,
Icon = item.icon,
Href = item.href,
Title = item.title,
};
rootNode.Child.Add(treeNode);
}
foreach (var item in rootNode.Child)
{
GetTreeNodeListByNoLockedDTOArray(systemMenuEntities, item);
}
}
}
```
> 最后将rootNode的Child 赋值返回给 MenusInfoResultDTO.MenuInfo 返回给前端就行
> 完整的后端示例地址: