EasyUI权限

思考:

我们想一个用户对应多个菜单
然后一个菜单可以对应多个用户
其实这就是user与menu的多对多的关系

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

创建dao

public class UserDao extends JsonBaseDao{

	/*
	 * 用户登录或者查询用户分页信息的公共方法
	 * */
	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+=" and uid = "+uid;
		}
		if(StringUtils.isNotBlank(upwd)) {
			sql+=" and upwd = "+upwd;
		}
		return super.executeQuery(sql, pageBean);
	}
	/*
	 * 根据当前用户登录的ID去查询对应的所有菜单
	 * */
	public List<Map<String, Object>> getMenuByUid(Map<String, String[]> paMap,PageBean pageBean) throws InstantiationException, IllegalAccessException, SQLException{
		String sql="select * from t_easyui_usermenu where true ";
		String uid=JsonUtils.getParamVal(paMap, "uid");
		if(StringUtils.isNotBlank(uid)) {
			sql+=" and uid = "+uid;
		}
		return super.executeQuery(sql, pageBean);
	}
}

修改原有的dao
在这里插入图片描述

web层UserAction

public class UserAction extends ActionSupport{
    private UserDao userDao=new UserDao();
	/*
	 * 登录后成功跳转index.jsp
	 * */
	public String login(HttpServletRequest req,HttpServletResponse resp) {
		try {
//			系统中是否有当前用户
			Map<String, Object> map =null;
			try {
				map= this.userDao.list(req.getParameterMap(), null).get(0);
			} catch (Exception e) {
				// TODO: handle exception
				req.setAttribute("msg", "此用户不存在");
				return "login";
			}
//			有
			if(map!=null && map.size()>0) {
//			查询用户的中间表,获取对应的menuId的集合
//				[{Menuid:002,...},{Menuid:003...}]
//				002,003
				StringBuilder sb=new StringBuilder();
				List<Map<String, Object>> menuIdArrays = this.userDao.getMenuByUid(req.getParameterMap(), null);
				for (Map<String, Object> m : menuIdArrays) {
					sb.append(","+m.get("menuId"));
				}
//					,002,003
				req.setAttribute("menuIds", sb.substring(1));
				return "index";
			}else {
//			没有
				req.setAttribute("msg", "此用户不存在");
				return "login";
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return "login";
		}
	}
}

新增登入界面,跳入前端树形菜单

<%@ 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">
uid:<input type="text" name="uid">
upwd:<input type="text" name="upwd">
<input type="submit">
<span style="color: red">${msg }</span>
</form>
</body>
</html>

在原有的jsp页面添加一个隐藏域,如果不使用隐藏域的话,js调用时会报错

<input type="hidden" id="menuIds" value="${menuIds }">

再在js中调用

 url:'menuAction.action?methodName=menuTree&&Menuid='+$("#menuIds").val(),

展示页面,登录哪个用户就查看哪些权限:
某几个权限
在这里插入图片描述
在这里插入图片描述
所有权限
在这里插入图片描述
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值