三星权限设计

权限设计
核心思路:

  1. 登录:查询数据库的用户名和密码,如果存在就登录进主界面
  2. 获取id: 创建方法并获取角色id(字段roleId),获取权限角色的集合
  3. 查询:同过查询权限获取的集合去获取菜单id
  4. 核心代码:创建类(loginDao)
  5. /** /**
    • 三星权限用户登录
    • @param paramMap
    • @param pageBean
    • @return
    • @throws InstantiationException
    • @throws IllegalAccessException
    • @throws SQLException
      */
      public List> userLoginThree(Map paramMap,PageBean pageBean) throws InstantiationException, IllegalAccessException, SQLException{
      String uid = JsonUtils.getParmeMap(paramMap, “uid”);
      String upwd = JsonUtils.getParmeMap(paramMap, “upwd”);
      String sql =“select * from t_easyui_user_version2 where 1=1”;
      if(StringUtils.isNotBlank(uid)) {
      sql +=" and uid = “+uid;
      }
      if(StringUtils.isNotBlank(upwd)) {
      sql +=” and upwd = "+upwd;
      }
      return super.executeQuery(sql, pageBean);
      }

/**
* 角色权限表的roleID
* @param paramMap
* @param pageBean
* @return
* @throws InstantiationException
* @throws IllegalAccessException
* @throws SQLException
*/
public List> getListFromUserThree(Map paramMap,PageBean pageBean) throws InstantiationException, IllegalAccessException, SQLException{
String roleId = JsonUtils.getParmeMap(paramMap, “roleId”);
String sql =“select * from t_easyui_menu_role where 1=1”;
if(StringUtils.isNotBlank(roleId)) {
sql +=" and roleId = "+roleId;
}
return super.executeQuery(sql, pageBean);
}`
创建LoginAction类配置xml文件中

/**
			 * 调用loginDao查询方法
			 */
			List> userLoginThree = this.loginDao.userLoginThree(req.getParameterMap() , null);
	         Map mapUserThree = userLoginThree.get(0);
	         if(mapUserThree != null) {
	        	  Map paramMap = new HashMap<>();
	        	  paramMap.put("roleId", new String[] {(String) mapUserThree.get("roleId").toString()});
	        	  /**
	        	   * 获取角色权限用户的信息
	        	   * 查询角色id
	        	   */
				 List> listFromUserTwo = this.loginDao.getListFromUserThree(paramMap , null);
					 StringBuffer sb = new StringBuffer();
				 for (Map map : listFromUserTwo) {
						 sb.append(",").append(map.get("menuId"));
						 System.out.println("角色表的权限"+sb.append(",").append(map.get("menuId")));
					}
				 /**
				  * 放入session集合中反馈到界面
				  */
				 req.getSession().setAttribute("menuId", sb.toString().substring(1));
	         }

你可能感兴趣的:(学习笔记)