×

sql mysql oracle

使用exists来做权限判断,struts2+spring+ibatis项目权限

我的笔记 我的笔记 发表于2018-09-27 14:36:02 浏览3390 评论0

抢沙发发表评论

使用exists来判断权限

1、比如一条数据中存在多个人员的权限,人员是多选的,比如项目表p_base_info和团队成员表p_base_info_user,团队成员表中有一个项目id和人员id,此时判断这个人的权限可以这样:

select p.l_id,p.vc_pro_name,p.vc_pro_code  p_base_info p 
where 1=1 and (
exists (select 1 from p_base_info_user pbu where pbu.l_user_id=21)
)

上边的的语句就是判断当前登录人id为21的人员,能否看到这条项目记录。

2、如果有多个人员权限呢,同样只需要把exists这个语句在复制一遍即可。

select p.l_id,p.vc_pro_name,p.vc_pro_code  p_base_info p 
where 1=1 and (
exists (select 1 from p_base_info_user pbu where pbu.l_user_id=21) or
exists (select 1 from p_base_info_user pbu where pbu.l_user_id=21)
)


我的笔记博客版权我的笔记博客版权