数据库设计--用户、角色及权限管理

关于用户、角色及权限管理。如下设计是在oracle数据库环境下demo.

 

1、table user(用户表)

 

-------------------------------------------------
  ID    username      password    name   ...
-------------------------------------------------
  1      admin         admin      测试1
  2       lx                  lx          测试2

 

2、table group(用户组)

 

-------------------------------------------------
  ID    name      description    ...
-------------------------------------------------
  1      js            技术人员
  2      yw          业务人员

 

3、table permission(权限及菜单表)

 

-------------------------------------------------------------------------------------
  ID   name    depth    parentid       link           description    showmenu    ...
-------------------------------------------------------------------------------------
  1  系统管理     1           0                                                              1
  2  用户管理     2           1                                                              1
  3  用户组管理  2           1                                                              1
  4  添加用户     3           2        /user/adduser.do                           1
  5  查询用户     3           2        /user/listuser.do                            1

 

说明:depth 为菜单级次,1为1级主菜单...

 

4、table user_permission(用户权限对照表)


-------------------------------------------------
  userId       permissionid
-------------------------------------------------


5、table group_permission(用户组权限对照表)


-------------------------------------------------
  groupId       permissionid
-------------------------------------------------
     2                1
     2                2
     2                3
     2                4
     2                5

6、table user_group(用户用户组对照表)


-------------------------------------------------
  userId            groupId 
-------------------------------------------------
     1                 2
     2                 2

 

7、Start with...Connect By子句递归查询

 

select p.id, p.name, p.link , p.depth , p.parentId, p.description , p.showAsMenu 
from permission p join  (select gp.permissionid from user_group ug 
join group_permission gp on ug.userid=1  and ug.groupid=gp.groupid union select up.permissionid 
from user_permission up where up.userid=1) t on p.id=t.permissionid and p.showasmenu=1 and p.depth<=3 
 start with p.parentid=1 connect by prior p.id=p.parentid order siblings by  p.id

 

O了, 显示效果就不写了!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值