easyui[2]

easyui[2]

用户的权限可以是一对多,也可以是多对多
一对多的弊端就是:一个菜单不能对应多个用户!

具体的思路的话就是以下这样子:
1.执行数据库脚本
2.修改原有的实体类
3.建立实体类
4.创建dao
5.修改原有的dao
6.新增web的方法
7.新增登入界面,跳入前端树形菜单

关于权限这一块在我的上一篇博客中有初步的了解:
接下来我们就开始写代码啦:
用户的dao方法:

package com.wt.dao;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import com.wt.util.JsonBaseDao;
import com.wt.util.JsonUtils;
import com.wt.util.PageBean;
import com.wt.util.StringUtils;



public class UserDao extends JsonBaseDao {
	
	/**
	 * 登录查询用户表    登录
	 * @return
	 * @throws SQLException 
	 * @throws IllegalAccessException 
	 * @throws InstantiationException 
	 */
	public List<Map<String, Object>> list(Map<String, String[]> paMap,PageBean pb) 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, pb);
	}
	
	/**
	 * 通过中间表查询登录用户所对应的权限
	 * @param paMap
	 * @param pb
	 * @return
	 * @throws InstantiationException
	 * @throws IllegalAccessException
	 * @throws SQLException
	 */
	public List<Map<String, Object>> listMenu(String uid,PageBean pb) 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, pb);
	}

}

在menudao中改变了一个小地方:

public List<Map<String, Object>> listMenuSef(Map<String, String[]> map,PageBean pb) 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, pb);
	}

在子控制器中

package com.wt.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.wt.dao.UserDao;
import com.zking.framework.ActionSupport;

public class UserAction extends ActionSupport {
	
	private UserDao ud=new UserDao();
	
	
	public String login(HttpServletRequest req,HttpServletResponse resp) throws InstantiationException, IllegalAccessException, SQLException {
		List<Map<String, Object>> list = this.ud.list(req.getParameterMap(), null);
		if(list!=null&&list.size()>0) {
			List<Map<String, Object>> listMenu = this.ud.listMenu(req.getParameter("uid"), null);
			StringBuilder sb=new StringBuilder();
			for (Map<String, Object> map : listMenu) {
				sb.append(","+map.get("menuId"));
			}
			//,001,002,.....
			req.setAttribute("menuHid", sb.substring(1));
		}
		else {
			return "login";
		}
		return "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">
<title>Insert title here</title>
</head>
<body>
<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>
</body>
</html>

index界面的话在上一篇博客有写:
结果如下:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值