在easyui1的基础上实现权限设置
二星权限设计(用户权限多对多)
1、执行数据库脚本
2、修改原有的实体类
3、建立实体类
4、创建dao
5、修改原有的dao
6、新增web的方法
7、新增登入界面,跳入前端树形菜单
项目大体结构如下:
在easyui1的基础上新加了一点
直接提供代码:
index.jsp
<%@ 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">
<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath}/static/easyui5/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath}/static/easyui5/themes/icon.css">
<script type="text/javascript"
src="${pageContext.request.contextPath}/static/easyui5/jquery.min.js"></script>
<!--这个依赖上面的js插件徐在上面的js插件下引用 -->
<script type="text/javascript"
src="${pageContext.request.contextPath}/static/easyui5/jquery.easyui.min.js"></script>
<script type="text/javascript"
src="${pageContext.request.contextPath}/static/js/index.js"></script>
<title>后台管理主界面</title>
</head>
<body class="easyui-layout">
<input type="hidden" id="menuIds" value="${menuIds}">
<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="menuTab" class="easyui-tabs" style="height: 800px;">
<div title="首页" style="padding: 20px; display: none;">欢迎界面</div>
</div>
</div>
</body>
</html>
login.jsp
<%@ 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>用户登录界面</title>
</head>
<body>
<form
action="${pageContext.request.contextPath}/userAction.action?methodName=login"
method="post">
uid:<input type="text" name="uid"><br> uname:<input
type="text" name="upwd"><br> <input type="submit"
value="ok">
</form>
</body>
</html>
UserAction.java
package com.wangcong.web;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.wangcong.dao.UserDao;
import com.zking.framework.ActionSupport;
public class UserAction extends ActionSupport {
private UserDao userDao=new UserDao();
public String login(HttpServletRequest req,HttpServletResponse resp) throws InstantiationException, IllegalAccessException, SQLException {
String code="index";
//登录
try {
List<Map<String, Object>> list=this.userDao.list(req.getParameterMap(), null);
if(list != null && list.size()==1) {
//用户存在
List<Map<String, Object>> menuList=this.userDao.getMenusByUser(req.getParameterMap(), null);
StringBuilder sb=new StringBuilder();
for (Map<String, Object> map : menuList) {
sb.append(","+map.get("menuId"));
}
req.setAttribute("menuIds", sb.substring(1));
}else {
//用户不存在
req.setAttribute("msg", "用户不存在");
code="login";
}
} catch (InstantiationException | IllegalAccessException | SQLException e) {
e.printStackTrace();
code="login";
}
return code;
}
}
UserDao.java
package com.wangcong.dao;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import com.wangcong.util.JsonBaseDao;
import com.wangcong.util.JsonUtils;
import com.wangcong.util.PageBean;
import com.wangcong.util.StringUtils;
public class UserDao extends JsonBaseDao {
/**
* 用于查询用户分页列表所用
* 用于登录所用
* @param map
* @param pageBean
* @return
* @throws SQLException
* @throws IllegalAccessException
* @throws InstantiationException
*/
public List<Map<String, Object>> list(Map<String, String[]> map,PageBean pageBean) throws InstantiationException, IllegalAccessException, SQLException{//写通用的
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+=" and uid ="+uid;
}
if(StringUtils.isNotBlank(upwd)) {
sql+=" and upwd ="+upwd;
}
return super.executeQuery(sql, pageBean);
}
/**
* 通过用户登录的唯一账号,在用户权限中间表中获取菜单Id的集合 查询结果
* @param map
* @param pageBean
* @return
* @throws InstantiationException
* @throws IllegalAccessException
* @throws SQLException
*/
public List<Map<String, Object>> getMenusByUser(Map<String, String[]> map,PageBean pageBean) throws InstantiationException, IllegalAccessException, SQLException{//写通用的
String sql="select * from t_easyui_usermenu where true";
String uid=JsonUtils.getParamVal(map, "uid");
if(StringUtils.isNotBlank(uid)) {
sql+=" and uid ="+uid;
}
return super.executeQuery(sql, pageBean);
}
}
index.js
$(function() {
$('#tt').tree({
// url:'menuAction.action?methodName=menuTree&&Menuid=001,002',
//变动态
url:'menuAction.action?methodName=menuTree&&Menuid='+$("#menuIds").val(),
onClick:function(node){
// alert(node.attribute.MenuURL);//在用户点击的时候提示
var content = '<iframe scrolling="no" frameborder="0" src="'+node.attribute.MenuURL+'" width="99%" height="99%"></iframe>';
if($("#menuTab").tabs('exists',node.text)){
$("#menuTab").tabs('select',node.text)
}else{
$('#menuTab').tabs('add',{
title:node.text,
content:content,
closable:true
});
}
}
});
})
登录后:
第二种:
登录后:、
最后一种:也是最大权限
结果: