权限树

news/2024/7/8 8:41:01 标签: permissions, stylesheet, tree, list, table, session

 权限系统示例应用程序
软件工程从需求,设计,编码,测试和发布等流程。
RBAC即基于角色的访问控制系统,它以角色role为中心构成。
用户->角色->  权限(操作,对象)
三个表person,role,permission. 中间表personRole,rolePermission,另一个表departement

 

 

dtree,下载地址是:
www.destroydrop.com/javascripts/tree
csdn空间5/tree.zip 包括dtree.js,dtree.css,img.
myFaces提供的tree2.

 

menu.jsp

<%@page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<f:view>
   <head>
      <title>A menu page</title>
      <link rel="StyleSheet" href="css/dtree.css" type="text/css" />
   </head>
  
   <body leftmargin="0" topmargin="0" bgcolor="#eeeeee">
     <table width="180">
       <tr>
         <td height="300" valign="top" nowrap>
           <script type="text/javascript" src="js/dtree.js"></script>
           <script type='text/javascript'>
              tree = new dTree('tree');
              tree.config.folderLinks=false;
              tree.config.useCookies=false;            
              <c:forEach var="permission" items="#{user.permissions}" >
                tree.add(
                   "<h:outputText value="#{permission.id}"/>",
                   "<h:outputText value="#{permission.pid}"/>",
                   "<h:outputText value="#{permission.name}"/>",
                   "<h:outputText value="#{permission.url}"/>",
                   "<h:outputText value="#{permission.title}"/>",
                   "<h:outputText value="#{permission.target}"/>",
                   "<h:outputText value="#{permission.icon}"/>"                  
                   );           
             </c:forEach>            
             document.write(tree);
          </script>
         </td>
       </tr>
     </table>
    </body>
</f:view>
</html>

 

 

用户登录

 List permissions=findPermission(personId);
                   //将该人员被指派的所有的权限保存在人员对象中,
                   //这个权限列表就是该用户登录后看到的树形菜单
                   person.setPermissions(permissions);

findPermission方法

//查询一个用户的权限,放在一个列表中,用于填充页面上的树型菜单
 public List findUserPermission(final String userId){
  return (List)getHibernateTemplate().execute(
    new HibernateCallback(){
     public Object doInHibernate(Session session)
                           throws HibernateException{
         /*
          * 这里采用了非常规的做法,具体是从
          * rolePermission表查询某些角色被指派的
          * 权限id,而这些角色是从personRole表
          * 中查出的指定用户所被指派的角色,并查询出
          * 这些权限的上级权限id,这样一直查询到整个树
          * 的根并将所查询出来的所有权限放在临时表
          * #userPermission和#permID中,
          * 然后,从临时表和权限表中查询出权限数据。
          * 最后将临时表删除。
          */
      String sSql =" select distinct permissionID into "
        +" #userPermission from rolepermission "
        +" where roleID in (select roleID from personRole "
        +" where personID=:uId ) "
        
                 +" select * into #permID from (select distinct "
                 +" substring(permissionID,1,2) as ID,"
                 +" '0' as pID from #userPermission "
                    
                 +" union select distinct substring(permissionID,1,4) "
                 +" as ID,substring(permissionID,1,2) as pID "
                 +" from #userPermission "
                    
                 +" union select distinct substring(permissionID,1,6) "
                 +" as ID,substring(permissionID,1,4) as pID from "
                 +" #userPermission "
                
                 +" union select distinct substring(permissionID,1,8) "
                 +" as ID,substring(permissionID,1,6) as pID from "
                 +" #userPermission "
                
                 +" union select distinct substring(permissionID,1,10) "
                 +" as ID,substring(permissionID,1,8) as pID from "
                 +" #userPermission ) "
                 +" as tab where datalength(ID)>datalength(pID) "
                  
                 +" insert #permID values('0','-1') "
                 +" drop table #userPermission "
                    
                 +" select {permission.*} from #permID i,permission "
                 +" permission where i.ID=permission.ID "

                 + "drop table #permID";
      //将查询出来的一个用户的所有的权限放入一个列表中
      List result=(List) session.createSQLQuery(sSql)
              .addEntity("permission", Permission.class)
              .setString("uId", userId).list();     
      //返回权限列表     
      return result;
     }
    }
   ,true); 

 

treeSkill">

http://www.niftyadmin.cn/n/1425394.html

相关文章

pytest参数化

import pytest import math#pytest参数化 pytest.mark.parametrize("base,exponent,expected",[(2,2,4),(2,3,8),(1,9,1),(0,9,0)],ids["case1","case2","case3","case4"] )def test_pow(base,exponent,expected):assert ma…

c++ 快速排序_快速入门基数排序

数据结构排序算法之基数排序演示_哔哩哔哩 (゜-゜)つロ 干杯~-bilibili​www.bilibili.com通过示例理解基数排序假设我们有 10 万个手机号码&#xff0c;希望将这 10 万个手机号码 从小到大排序&#xff0c;你有什么比较快速的排序方法呢&#xff1f;归并排序、快排&#xff0c…

pytest运行测试

-s&#xff1a;用于关闭捕捉&#xff0c;从而输出打印信息 -v&#xff1a;用于增加测试用例冗长 -q&#xff1a;减少测试的运行冗长&#xff0c;也可以用--quiet代替 -k&#xff1a;运行名称中包含某字符串的测试用例 例如&#xff1a;pytest -k add test_assert.py 运行t…

python软件如何安装方法_Python如何发布程序的详细教程

如何发布一个Python程序&#xff1a; 1.安装一个pyInstaller 在pycharm里点 file —–>setting—–>Project workspace——>Interpreter——>点pip右边的&#xff0b;号&#xff0c;进入下面这个界面&#xff1a;搜索pyInstaller, 点击左下方Iinstall package安装&…

sqlserver之临时表 中间表

本地临时表的名称前面有一个编号符 (#table_name)&#xff0c;而全局临时表的名称前面有两个编号符 (##table_name)。 像一些老式的系统中&#xff0c;中间表一般都是使用组合主键&#xff0c;但是处理起来非常麻烦&#xff0c;所以&#xff0c;Hibernate强烈建议不要使这种主…

python自带的编辑器快捷键_Python入门之PyCharm的快捷键与常用设置和扩展(Mac系统)...

1. 快捷键 2 . PyCharm的常用设置和扩展 --------------------------------------------------------------------------------------------------------------------------------------------------------- Mac键盘符号和修饰键说明⌘ Command ⇧ Shift ⌥ Option ⌃ Control …

jsf中传值到javascript中

jsf中传值到javascript中 就可以直接传的&#xff0e;${pBean.url} url地址中含中文乱码的解决&#xff1a; <Connector port"8080" protocol"HTTP/1.1" URIEncoding"UTF-8" connectionTimeout"20000" …

python用的什么编码_python,编码_这是什么编码,如何解码,python,编码 - phpStudy

这是什么编码&#xff0c;如何解码 b\x08\x91\x9a\x8c\xb0\x01\x10\x86\x01\x1a\x0fiPhone OS 9.2.1"\x80\x04\x8f\x05\x18\xa8\xdf\xaf_\xe7\x0c\xfc\x92\xd9\xbe\x98\xb7\x88\x88| \xe2\xccX\xb3lw[\xf2\x12x\xed^\xd5\xcaO\x11\x8d\x02\xa4\xfad0\xc67\xa5$\xe4\xaf\x9…