1. 表结构
/*Navicat Premium Data TransferSource Server : 127.0 .0.1Source Server Type : MySQLSource Server Version : 80026 Source Host : localhost:3306Source Schema : sys-adminTarget Server Type : MySQLTarget Server Version : 80026 File Encoding : 65001 Date: 12 /09/2022 19 :05:15
*/SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0 ; -- ----------------------------
-- Table structure for sys_permission
-- ----------------------------
DROP TABLE IF EXISTS ` sys_permission` ;
CREATE TABLE ` sys_permission` ( ` id ` int NOT NULL AUTO_INCREMENT COMMENT '权限ID' ,` permName` varchar( 50 ) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '权限名称' ,` permTag` varchar( 50 ) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '菜单标签' ,` url` varchar( 255 ) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '请求url' ,PRIMARY KEY ( ` id ` ) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 2000 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '权限表' ROW_FORMAT = Dynamic; -- ----------------------------
-- Records of sys_permission
-- ----------------------------
INSERT INTO ` sys_permission` VALUES ( 1 , '查询用户' , 'select' , '/select' ) ;
INSERT INTO ` sys_permission` VALUES ( 2 , '添加用户' , 'insert' , '/insert' ) ;
INSERT INTO ` sys_permission` VALUES ( 3 , '修改用户' , 'update' , '/update' ) ;
INSERT INTO ` sys_permission` VALUES ( 4 , '删除用户' , 'delete' , '/delete' ) ; -- ----------------------------
-- Table structure for sys_role
-- ----------------------------
DROP TABLE IF EXISTS ` sys_role` ;
CREATE TABLE ` sys_role` ( ` id ` int NOT NULL AUTO_INCREMENT COMMENT '角色ID' ,` roleName` varchar( 50 ) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '角色名称' ,` roleDesc` varchar( 50 ) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '角色说明' ,PRIMARY KEY ( ` id ` ) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 100 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '角色信息表' ROW_FORMAT = Dynamic; -- ----------------------------
-- Records of sys_role
-- ----------------------------
INSERT INTO ` sys_role` VALUES ( 1 , 'admin' , '管理员' ) ;
INSERT INTO ` sys_role` VALUES ( 2 , 'add_user' , '添加管理员' ) ; -- ----------------------------
-- Table structure for sys_role_permission
-- ----------------------------
DROP TABLE IF EXISTS ` sys_role_permission` ;
CREATE TABLE ` sys_role_permission` ( ` role_id` int NOT NULL COMMENT '角色ID' ,` perm_id` int NOT NULL COMMENT '权限ID' ,PRIMARY KEY ( ` role_id` , ` perm_id` ) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '角色和权限关联表' ROW_FORMAT = Dynamic; -- ----------------------------
-- Records of sys_role_permission
-- ----------------------------
INSERT INTO ` sys_role_permission` VALUES ( 1 , 1 ) ;
INSERT INTO ` sys_role_permission` VALUES ( 1 , 2 ) ;
INSERT INTO ` sys_role_permission` VALUES ( 1 , 3 ) ;
INSERT INTO ` sys_role_permission` VALUES ( 1 , 4 ) ;
INSERT INTO ` sys_role_permission` VALUES ( 2 , 2 ) ; -- ----------------------------
-- Table structure for sys_user
-- ----------------------------
DROP TABLE IF EXISTS ` sys_user` ;
CREATE TABLE ` sys_user` ( ` id ` int NOT NULL AUTO_INCREMENT COMMENT '用户ID' ,` dept_id` varchar( 50 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '部门ID' ,` name` varchar( 50 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '姓名' ,` user_name` varchar( 30 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '登录名称' ,` email` varchar( 50 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '用户邮箱' ,` phone_number` varchar( 11 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '手机号码' ,` SEX` char( 1 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '0' COMMENT '性别 0-男 1-女 2-未知' ,` avatar` varchar( 100 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '头像地址' ,` password` varchar( 100 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '密码' ,` salt` varchar( 50 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '盐值' ,` birthday` date NULL DEFAULT NULL COMMENT '生日' ,` status` char( 1 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '0' COMMENT '账号状态(0-正常 1-停用)' ,` del_flag` char( 1 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '0' COMMENT '删除状态(0-正常 1-停用)' ,` login_ip` varchar( 128 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '最后登录IP' ,` login_date` date NULL DEFAULT NULL COMMENT '最后登录时间' ,` create_time` datetime NULL DEFAULT NULL COMMENT '创建时间' ,` update_by` datetime NULL DEFAULT NULL COMMENT '更新者' ,` remark` varchar( 500 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '备注' ,` version` int NULL DEFAULT NULL COMMENT '版本' ,` open_id` varchar( 100 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '微信唯一标识' ,PRIMARY KEY ( ` id ` ) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '用户信息表' ROW_FORMAT = Dynamic; -- ----------------------------
-- Records of sys_user
-- ----------------------------
INSERT INTO ` sys_user` VALUES ( 1 , NULL, '管理员' , 'admin' , NULL, '17610135215' , '0' , '' , '$2a$10$TDQ5efFuROKwPJq.BZtNd.HJGJNoo/larDrZjGA.57Y4J1KJiaXmG' , NULL, '2022-09-12' , '0' , '0' , '' , NULL, NULL, NULL, NULL, NULL, NULL) ; -- ----------------------------
-- Table structure for sys_user_role
-- ----------------------------
DROP TABLE IF EXISTS ` sys_user_role` ;
CREATE TABLE ` sys_user_role` ( ` user_id` int NOT NULL COMMENT '用户ID' ,` role_id` int NOT NULL COMMENT '角色ID' ,PRIMARY KEY ( ` user_id` , ` role_id` ) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '用户和角色关联表' ROW_FORMAT = Dynamic; -- ----------------------------
-- Records of sys_user_role
-- ----------------------------
INSERT INTO ` sys_user_role` VALUES ( 1 , 1 ) ;
INSERT INTO ` sys_user_role` VALUES ( 2 , 2 ) ; SET FOREIGN_KEY_CHECKS = 1 ;
2. 权限查询sql
SELECTpermission.*
FROMsys_user uINNER JOIN sys_user_role user_role ON u.id = user_role.user_idINNER JOIN sys_role_permission role_permission ON user_role.role_id = role_permission.role_idINNER JOIN sys_permission permission ON role_permission.perm_id = permission.id
WHEREu.user_name = 'admin'