1、权限控制功能,其核心思路是控制某“用户”所属“角色”可以访问哪些“角色”,可以访问哪些“功能”。
在前后端分离架构模式下,功能实现是基于“接口”进行的,所以“功能”和“页面”会分别和“接口”所关联。
2、所以数据库中,至少有以上5张表,分别为:用户信息表、角色表、页面信息表,接口信息表,功能信息表,并且分别建立彼此之间的关联表
创建表结构sql语句如下:
CREATE TABLE `api_info` (
`api_id` int(11) NOT NULL,
`name` varchar(255) DEFAULT NULL,
`url` varchar(255) DEFAULT NULL,
PRIMARY KEY (`api_id`),
CONSTRAINT `api_info_ibfk_1` FOREIGN KEY (`api_id`) REFERENCES `function_api_relation` (`api_id`),
CONSTRAINT `api_info_ibfk_2` FOREIGN KEY (`api_id`) REFERENCES `page_api_relation` (`api_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `function_api_relation` (
`id` int(11) NOT NULL,
`function_id` int(11) DEFAULT NULL,
`api_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `api_id` (`api_id`),
KEY `function_id` (`function_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `function_info` (
`function_id` int(11) NOT NULL,
`name` varchar(255) DEFAULT NULL,
PRIMARY KEY (`function_id`),
CONSTRAINT `function_info_ibfk_1` FOREIGN KEY (`function_id`) REFERENCES `function_api_relation` (`function_id`),
CONSTRAINT `function_info_ibfk_2` FOREIGN KEY (`function_id`) REFERENCES `function_page_relation` (`function_id`),
CONSTRAINT `function_info_ibfk_3` FOREIGN KEY (`function_id`) REFERENCES `function_rule_relation` (`function_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `function_page_relation` (
`id` int(11) DEFAULT NULL,
`function_id` int(11) DEFAULT NULL,
`page_id` int(11) DEFAULT NULL,
KEY `function_id` (`function_id`),
KEY `page_id` (`page_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `function_rule_relation` (
`id` int(11) NOT NULL,
`function_id` int(11) DEFAULT NULL,
`rule_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `function_id` (`function_id`),
KEY `rule_id` (`rule_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `page_api_relation` (
`id` int(11) NOT NULL,
`page_id` int(11) DEFAULT NULL,
`api_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `page_id` (`page_id`),
KEY `api_id` (`api_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `page_info` (
`page_id` int(11) DEFAULT NULL,
`name` varchar(255) DEFAULT NULL,
`uri` varchar(255) DEFAULT NULL,
`parent_id` int(11) DEFAULT NULL,
`level` varchar(255) DEFAULT NULL,
KEY `page_id` (`page_id`),
CONSTRAINT `page_info_ibfk_1` FOREIGN KEY (`page_id`) REFERENCES `page_rule_relation` (`page_id`),
CONSTRAINT `page_info_ibfk_2` FOREIGN KEY (`page_id`) REFERENCES `page_api_relation` (`page_id`),
CONSTRAINT `page_info_ibfk_3` FOREIGN KEY (`page_id`) REFERENCES `function_page_relation` (`page_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `page_rule_relation` (
`id` int(11) NOT NULL,
`page_id` int(11) DEFAULT NULL,
`rule_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `page_id` (`page_id`),
KEY `rule_id` (`rule_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `rule_info` (
`rule_id` int(11) NOT NULL COMMENT '角色id',
`name` varchar(100) DEFAULT NULL,
`status` varchar(10) DEFAULT NULL,
`create_time` datetime DEFAULT NULL,
PRIMARY KEY (`rule_id`),
CONSTRAINT `rule_info_ibfk_1` FOREIGN KEY (`rule_id`) REFERENCES `user_rule_relation` (`rule_id`),
CONSTRAINT `rule_info_ibfk_2` FOREIGN KEY (`rule_id`) REFERENCES `page_rule_relation` (`rule_id`),
CONSTRAINT `rule_info_ibfk_3` FOREIGN KEY (`rule_id`) REFERENCES `function_rule_relation` (`rule_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `user_info` (
`user_id` int(11) NOT NULL COMMENT '用户id',
`username` varchar(100) DEFAULT NULL COMMENT '用户名',
`password` varchar(200) DEFAULT NULL COMMENT '密码',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
PRIMARY KEY (`user_id`),
CONSTRAINT `user_info_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user_rule_relation` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户信息表';
CREATE TABLE `user_rule_relation` (
`id` int(11) NOT NULL,
`user_id` int(11) DEFAULT NULL,
`rule_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`),
KEY `rule_id` (`rule_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;