アクセス権の木
いわゆる権:
これは、異なるユーザが異なるリソースでシステムを操作できるようにすることです
直接異なるユーザが左側に別のメニューを見ることができることを指します
いわゆる役割:
これは(アクセス権の文字セットに対応するそれぞれが)システムにおける特権のセットを指します
1、スター意匠権(多くのユーザーの権利)
?データベーススクリプトを実行するには
?エンティティクラスを設立
DAOの作成?
?作成したWeb層を
?表示メニューツリーを変更
口座番号とパスワードの検索によってmenuID属性の中に入るために、メニューのIDを取得することですが、ロードすることができ、対応するメニューまたはサブメニュー:アイデアの実現
2.デザイン賞権限(ユーザー権限-多くの)
?データベーススクリプトのSQLを実行する
?既存のエンティティクラスを変更
?エンティティクラスを設立
?DAOのメソッドを作成
?権限テーブル方式の一連の書き込み
方法を?新しいwebservlet
?ログインを追加します。インターフェイス、各設定メニューの権限の前端に対応するメニューツリー表示ジャンプ
アイデアの実現:ユーザーのクエリデータテーブルは、テーブルの真ん中にいたuidで(テーブルのUID真ん中をチェックする方法)は、複数のデータに対応するアクセス許可セットを取得し、コレクションに見つかりUIDを横断するために登録し、各マップのコレクションをステッチされたのに代わって上陸しましたmenuID属性(このコレクションをmenuID属性における親子関係の複数のセットと、デジタルの方法が提供されています)
アクセス権テーブル:
ユーザーテーブル:
テーブルのアクセス権の真ん中:
ログイン画面を書きます:
<form action="${pageContext.request.contextPath }/userAction.action?methodName=login" method="post"> uid:<input type="text" name="uid"><br> upwd:<input type="text" name="upwd"><br> <input type="submit" > </form>
配置 mvc.xml
<?xml version="1.0" encoding="UTF-8"?> <config> <!-- <action path="/regAction" type="test.RegAction"> <forward name="failed" path="/reg.jsp" redirect="false" /> <forward name="success" path="/login.jsp" redirect="true" /> </action> --> <action path="/menuAction" type="com.chenjiahao.web.MenuAction"> <forward name="index" path="/index.jsp" redirect="false" /> </action> <action path="/userAction" type="com.chenjiahao.web.UserAction"> <forward name="index" path="/index.jsp" redirect="false" /> </action> </config>
登录后台
判断是否有这个人
返回这个人的权限
package com.chenjiahao.dao; import java.util.List; import java.util.Map; import com.chenjiahao.util.JsonBaseDao; import com.chenjiahao.util.JsonUtils; import com.chenjiahao.util.PageBean; import com.chenjiahao.util.StringUtils; public class UserDao extends JsonBaseDao { /** * 登录查询用户表 * * @param map * @param pageBean * @return * @throws Exception */ public List<Map<String, Object>> list(Map<String, String[]> map, PageBean pageBean) throws Exception { String sql = "SELECT *FROM t_easyui_user_version2 WHERE TRUE"; String uid = JsonUtils.getParamVal(map, "uid"); String upwd = JsonUtils.getParamVal(map, "upwd"); if (StringUtils.isNotBlank(uid)) { sql = sql + " and uid=" + uid; } if (StringUtils.isNotBlank(upwd)) { sql = sql + " and upwd=" + upwd; } return super.executeQuery(sql, null); } /** * 通过中间表查询登录用户所对应的权限 * * @param string * @param pageBean * @return * @throws Exception */ public List<Map<String, Object>> listMenu(String uid, PageBean pageBean) throws Exception { String sql = "SELECT*FROM t_easyui_usermenu WHERE TRUE"; if (StringUtils.isNotBlank(uid)) { sql = sql + " and uid=" + uid; } return super.executeQuery(sql, null); } }
开始执行:
public class UserAction extends ActionSupport {
private UserDao userDao = new UserDao();
/**
* @param request
* @param response
* @return
* @throws Exception
*/
public String login(HttpServletRequest request, HttpServletResponse response) throws Exception {
List<Map<String, Object>> list = this.userDao.list(request.getParameterMap(), null);
if (list != null && list.size() > 0) {
List<Map<String, Object>> listMenu = this.userDao.listMenu(request.getParameter("uid"), null);
StringBuilder sb = new StringBuilder();
for (Map<String, Object> map : listMenu) {
sb.append("," + map.get("menuId"));
}
request.setAttribute("menuHid", sb.substring(1));
} else {
return "login";
}
return "index";
}
}
获取到登陆后的权限信息后就传到Index.jsp了
<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;"> tab1 </div> </div> </div> </body>
就是获取到信息,然后进行路径的跳转
$(function() { $('#tt') .tree( { url : 'menuAction.action?methodName=treeMenu&&menuHid='+$("#menuHid").val(), onClick : function(node) { var content = '<iframe scrolling="no" frameborder="0" src="' + node.attributes.menuURL + '" width="99%" height="99%"></iframe>'; if ($('#menuTabs').tabs('exists', node.text)) { $('#menuTabs').tabs('select', node.text) } else { $('#menuTabs').tabs('add', { title : node.text, content : content, closable : true, tools : [ { iconCls : 'icon-mini-refresh', handler : function() { alert('refresh'); } } ] }); } } }); })
菜单查询:
package com.chenjiahao.dao; import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import com.chenjiahao.entity.TreeNode; import com.chenjiahao.util.JsonBaseDao; import com.chenjiahao.util.JsonUtils; import com.chenjiahao.util.PageBean; import com.chenjiahao.util.StringUtils; public class MenuDao extends JsonBaseDao { private static final Map<String, String[]> TreeNode = null; /** * * @param map * request.getParameterMap * @param pageBean * 分页 * @return * @throws SQLException * @throws IllegalAccessException * @throws InstantiationException */ public List<TreeNode> list(Map<String, String[]> map, PageBean pageBean) throws Exception { List<Map<String, Object>> listMenu = this.listMenuSet(map, pageBean); List<TreeNode> treeNodeList = new ArrayList<>(); menu2TreeNodelist(listMenu, treeNodeList); return treeNodeList; } public List<Map<String, Object>> listMenuSet(Map<String, String[]> map, PageBean pageBean) throws Exception { 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); } /** * 查询menu表的数据 * * @param map * @param pageBean * @return * @throws SQLException * @throws IllegalAccessException * @throws InstantiationException */ public List<Map<String, Object>> listMenu(Map<String, String[]> map, PageBean pageBean) throws Exception { String sql = "select * from t_easyui_menu where true"; String id = JsonUtils.getParamVal(map, "id"); if (StringUtils.isNotBlank(id)) { sql = sql + " and parentid=" + id; } else { sql = sql + " and parentid=-1"; } return super.executeQuery(sql, pageBean); } /** * menu表的数据格式不符合easyui树形展示格式 需要转换成easyui所能识别的格式 * * @param map * @param treeNode * @throws SQLException * @throws IllegalAccessException * @throws InstantiationException */ private void menu2TreeNode(Map<String, Object> map, TreeNode treeNode) throws Exception { treeNode.setId(map.get("Menuid").toString()); treeNode.setText(map.get("Menuname").toString()); treeNode.setAttributes(map); // 递归 Map<String, String[]> jspMap = new HashMap<>(); jspMap.put("id", new String[] { treeNode.getId() }); List<Map<String, Object>> listMenu = this.listMenu(jspMap, null); List<TreeNode> treeNodeList = new ArrayList<>(); // 循环将数据取出来 menu2TreeNodelist(listMenu, treeNodeList); treeNode.setChildren(treeNodeList); } private void menu2TreeNodelist(List<Map<String, Object>> mapList, List<TreeNode> treeNodeList) throws Exception { TreeNode treeNode = null; for (Map<String, Object> map : mapList) { treeNode = new TreeNode(); menu2TreeNode(map, treeNode); treeNodeList.add(treeNode); } } }
效果图