三星权限设计
程序员文章站
2022-06-03 21:37:46
...
权限设计
核心思路:
- 登录:查询数据库的用户名和密码,如果存在就登录进主界面
- 获取id: 创建方法并获取角色id(字段roleId),获取权限角色的集合
- 查询:同过查询权限获取的集合去获取菜单id
- 核心代码:创建类(loginDao)
-
/**
/**- 三星权限用户登录
- @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));
}
上一篇: 原生js二级联动
下一篇: java定时器的几种用法