EasyUI权限

EasyUI权限:

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

1、一星权限设计(用户权限多对一)

2、二星权限设计(用户权限多对多)

接下来我们就做一个三表的权限

1用户表(t_easyui_user_version2)

2.用户菜单中间表(t_easyui_usermenu)

3.菜单表(t_easyui_menu)

 然后再写一个登陆界面,负责登陆各个人物权限

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

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

 1 public class UserDao extends JsonBaseDao {
 2     
 3     /**
 4      * 登陆查询用户表 
 5      * @param paMap
 6      * @param pageBean
 7      * @return
 8      * @throws SQLException 
 9      * @throws IllegalAccessException 
10      * @throws InstantiationException 
11      */
12        public List<Map<String, Object>> list(Map<String, String[]> paMap,PageBean pageBean) throws InstantiationException, IllegalAccessException, SQLException{
13            String sql="select * from t_easyui_user_version2 where true";
14            String uid=JsonUtils.getParamVal(paMap, "uid");
15            String upwd=JsonUtils.getParamVal(paMap, "upwd");
16            if(StringUtils.isNotBlank(uid)) {
17                sql=sql+" and uid="+uid;
18            }
19            if(StringUtils.isNotBlank(upwd)) {
20                sql=sql+" and upwd="+upwd;
21            }
22            
23         return super.executeQuery(sql, pageBean);
24                   
25        }
26        
27        /**
28         * 通过中间表查询登陆用户所对应的权限
29         * @param paMap
30         * @param pageBean
31         * @return
32         * @throws InstantiationException
33         * @throws IllegalAccessException
34         * @throws SQLException
35         */
36        public List<Map<String, Object>> listMenu(String uid,PageBean pageBean) throws InstantiationException, IllegalAccessException, SQLException{
37            String sql="select * from t_easyui_usermenu where true";
38            
39            if(StringUtils.isNotBlank(uid)) {
40                sql=sql+" and uid="+uid;
41            }
42         return super.executeQuery(sql, pageBean);
43            
44        }
45 }

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

 1 public class UserAction extends ActionSupport {
 2     private UserDao userDao=new UserDao();
 3     
 4    public String login(HttpServletRequest req,HttpServletResponse resp) {
 5        try {
 6            List<Map<String, Object>> list=    this.userDao.list(req.getParameterMap(), null);
 7            if(list!=null&&list.size()>0) {
 8                List<Map<String, Object>>listMenu= this.userDao.listMenu(req.getParameter("uid"), null);
 9                StringBuilder sb=new StringBuilder();
10                for (Map<String, Object> map : listMenu) {
11                 sb.append(","+map.get("menuId"));
12             }
13                req.setAttribute("menuHid", sb.substring(1));
14            }else {
15                return "login";
16            }
17     } catch (Exception e) {
18         // TODO Auto-generated catch block
19         e.printStackTrace();
20     }
21     return "index";

tree结构中加一个方法。

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

然后在首页中引用

 1 <body class="easyui-layout">
 2 <input type="hidden" id="menuHid" value="${menuHid }">
 3 
 4     <div data-options="region:'north',border:false" style="height:60px;background:#B3DFDA;padding:10px">north region</div>
 5     <div data-options="region:'west',split:true,title:'West'" style="width:150px;padding:10px;">
 6     后台管理界面的菜单
 7     <ul id="tt"></ul>  
 8     </div>
 9     <div data-options="region:'east',split:true,collapsed:true,title:'East'" style="width:100px;padding:10px;">east region</div>
10     <div data-options="region:'south',border:false" style="height:50px;background:#A9FACD;padding:10px;">south region</div>
11     <div data-options="region:'center',title:'Center'">
12     <div id="menuTabs" class="easyui-tabs" style="">   
13     <div title="Tab1" style="padding:20px;display:none;">   
14        欢迎使用   
15     </div>   
16     
17 </div>  
18     
19     </div>
20 </body>
21 
22 </html>

运行之后:

登陆成功,跳转到用户对应的权限

 完成。

猜你喜欢

转载自www.cnblogs.com/AluoKa/p/11013387.html
今日推荐