欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

三星权限设计

程序员文章站 2022-06-03 21:37:46
...

权限设计
核心思路:

  1. 登录:查询数据库的用户名和密码,如果存在就登录进主界面
  2. 获取id: 创建方法并获取角色id(字段roleId),获取权限角色的集合
  3. 查询:同过查询权限获取的集合去获取菜单id
  4. 核心代码:创建类(loginDao)
  5. /** /**
    • 三星权限用户登录
    • @param paramMap
    • @param pageBean
    • @return
    • @throws InstantiationException
    • @throws IllegalAccessException
    • @throws SQLException
      */
      public List<Map<String, Object>> userLoginThree(Map<String, String[]> 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<Map<String, Object>> getListFromUserThree(Map<String, String[]> 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<Map<String, Object>> userLoginThree = this.loginDao.userLoginThree(req.getParameterMap() , null);
	         Map<String, Object> mapUserThree = userLoginThree.get(0);
	         if(mapUserThree != null) {
	        	  Map<String, String[]> paramMap = new HashMap<>();
	        	  paramMap.put("roleId", new String[] {(String) mapUserThree.get("roleId").toString()});
	        	  /**
	        	   * 获取角色权限用户的信息
	        	   * 查询角色id
	        	   */
				 List<Map<String, Object>> listFromUserTwo = this.loginDao.getListFromUserThree(paramMap , null);
					 StringBuffer sb = new StringBuffer();
				 for (Map<String, Object> 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));
	         }
相关标签: 权限设置