EasyUI权限

EasyUI权限:

不同角色的人登录应该看到不同的权限和内容.

1、一星权限设计(用户权限多对一)
在这里插入图片描述
2、二星权限设计(用户权限多对多)
在这里插入图片描述
接下来我们就做一个三表的权限
1用户表(t_easyui_user_version2)
在这里插入图片描述
2.用户菜单中间表(t_easyui_usermenu)
在这里插入图片描述
3.菜单表(t_easyui_menu)
在这里插入图片描述
然后再写一个登陆界面,负责登陆各个人物权限

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="${pageContext.request.contextPath }/userAction.action?methodName=login" method="post">
账号:<input type="text" name="uid"><br>
密码:<input type="password" name="upwd"><br>
<input type="submit"><br>

</form>
</body>
</html>

写对应的dao方法,根据用户ID来查询用户对应的权限。

public class UserDao extends JsonBaseDao {
    
    /**
     * 登陆查询用户表 
     * @param paMap
     * @param pageBean
     * @return
     * @throws SQLException 
     * @throws IllegalAccessException 
     * @throws InstantiationException 
     */
       public List<Map<String, Object>> list(Map<String, String[]> paMap,PageBean pageBean) throws InstantiationException, IllegalAccessException, SQLException{
           String sql="select * from t_easyui_user_version2 where true";
           String uid=JsonUtils.getParamVal(paMap, "uid");
           String upwd=JsonUtils.getParamVal(paMap, "upwd");
           if(StringUtils.isNotBlank(uid)) {
               sql=sql+" and uid="+uid;
           }
           if(StringUtils.isNotBlank(upwd)) {
               sql=sql+" and upwd="+upwd;
           }
           
        return super.executeQuery(sql, pageBean);
                  
       }
       
       /**
        * 通过中间表查询登陆用户所对应的权限
        * @param paMap
        * @param pageBean
        * @return
        * @throws InstantiationException
        * @throws IllegalAccessException
        * @throws SQLException
        */
       public List<Map<String, Object>> listMenu(String uid,PageBean pageBean) throws InstantiationException, IllegalAccessException, SQLException{
           String sql="select * from t_easyui_usermenu where true";
           
           if(StringUtils.isNotBlank(uid)) {
               sql=sql+" and uid="+uid;
           }
        return super.executeQuery(sql, pageBean);
           
       }
}

web层自控制器来调用dao方法

public class UserAction extends ActionSupport {
    private UserDao userDao=new UserDao();
    
   public String login(HttpServletRequest req,HttpServletResponse resp) {
       try {
           List<Map<String, Object>> list=    this.userDao.list(req.getParameterMap(), null);
           if(list!=null&&list.size()>0) {
               List<Map<String, Object>>listMenu= this.userDao.listMenu(req.getParameter("uid"), null);
               StringBuilder sb=new StringBuilder();
               for (Map<String, Object> map : listMenu) {
                sb.append(","+map.get("menuId"));
            }
               req.setAttribute("menuHid", sb.substring(1));
           }else {
               return "login";
           }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return "index";

tree结构中加一个方法。

public   List<Map<String, Object>> listMenuSef(Map<String, String[]> map,PageBean pageBean) throws InstantiationException, IllegalAccessException, SQLException{
           String sql="select * from t_easyui_menu where true";
           String id=JsonUtils.getParamVal(map, "menuHid");
           if(StringUtils.isNotBlank(id)) {
               sql=sql+" and menuid in ("+id+")";
           }else {
               sql=sql+" and menuid = -1";
           }
           return super.executeQuery(sql, pageBean);

          }

然后在首页中引用

<body class="easyui-layout">
<input type="hidden" id="menuHid" value="${menuHid }">

    <div data-options="region:'north',border:false" style="height:60px;background:#B3DFDA;padding:10px">north region</div>
    <div data-options="region:'west',split:true,title:'West'" style="width:150px;padding:10px;">
    后台管理界面的菜单
    <ul id="tt"></ul>  
    </div>
    <div data-options="region:'east',split:true,collapsed:true,title:'East'" style="width:100px;padding:10px;">east region</div>
    <div data-options="region:'south',border:false" style="height:50px;background:#A9FACD;padding:10px;">south region</div>
    <div data-options="region:'center',title:'Center'">
    <div id="menuTabs" class="easyui-tabs" style="">   
    <div title="Tab1" style="padding:20px;display:none;">   
       欢迎使用   
    </div>   
    
</div>  
    
    </div>
</body>

</html>

运行之后:
在这里插入图片描述
登陆成功,跳转到用户对应的权限
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值