golang實現無限級選單 beego框架下

2022-05-06 22:57:12 字數 1828 閱讀 4575

資料表如下

-- ----------------------------

-- table structure for `auth_menu`

-- ----------------------------

drop table if exists `auth_menu`;

create table `auth_menu` (

`id` int(10) unsigned not null auto_increment,

`pid` int(11) not null comment '父級選單id',

`name` char(20) not null comment '選單名單',

`sort` tinyint(4) default '0' comment '排序值',

`route` varchar(60) default '' comment '跳轉鏈結',

primary key (`id`),

key `pid` (`pid`)

) engine=innodb auto_increment=24 default charset=utf8mb4 comment='許可權管理_選單表';

-- ----------------------------

-- records of auth_menu

-- ----------------------------

insert into `auth_menu` values ('14', '0', '設定', '1', '');

insert into `auth_menu` values ('15', '14', '許可權管理', '1', '');

insert into `auth_menu` values ('16', '14', '我的設定', '2', '');

insert into `auth_menu` values ('18', '15', '角色列表', '2', '/auth/role');

insert into `auth_menu` values ('19', '15', '許可權列表', '3', '/auth/permission');

insert into `auth_menu` values ('20', '15', '行為列表', '4', '/auth/action');

insert into `auth_menu` values ('21', '15', '選單列表', '5', '/auth/menu');

insert into `auth_menu` values ('22', '16', '基本資訊', '1', '/administrator/admininfo');

insert into `auth_menu` values ('23', '15', '管理員列表', '8', '/auth/administrator');

檔案 menu.go (使用beego orm)

type menu struct 

type treelist struct

func init()

func (m *menu)tablename() string

/**選單列表

*/func (m *menu)menulist() *treelist

/**遞迴獲取樹形選單

*/func (m *menu)getmenu(pid int) *treelist

for _, v := range menu

node.children = child

}return treelist

}

使用tree實現無限級樹形選單

使用tree實現無限級樹形選單 使用tree實現無限級樹形選單 單張表 sqlconnection con new sqlconnection configurationmanager.connectionstrings 字串 connectionstring string cmdtext sele...

選單無限級設計思路

這思路估計在高手眼中不算什麼 下面這個是乙個編碼無限級選單 id myselfcode 選單每級編號限制2位數字 這種思路方便排序 麻煩的是錄入編碼問題 需要在pojo中的新增屬性 而新增的屬性又不會對映到資料庫中 idmyselfcode parentcode 上級編碼 parentname 上級...

無限級選單簡單的設計

策略 資料庫就一張表,前端查詢出所有的可顯示的選單,在前端進行迴圈展示。create table sys menu id intnot null auto increment,name varchar 64 not null url varchar 255 pid intnot null defau...