为什么要权限:
权限目的:
是为了让不同的用户可以操作系统中不同资源
直接点说就是不同的用户可以看到左侧不同的菜单
思路:
1、菜单不同的原因在于,利用不同menuid进行查询,原本默认查询的是所有菜单,是通过-1去查的;
2、menuid由来:是登录用户id查询中间表数据所得来的
package com.lww.dao;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.lww.entity.TreeNode;
import com.lww.util.JsonBaseDao;
import com.lww.util.JsonUtils;
import com.lww.util.PageBean;
import com.lww.util.StringUtils;
public class MenuDao extends JsonBaseDao{
/**
* 给前台返回tree_data1.json的字符串
* 从前台jsp传递过来的参数集合
*/
public List
List
package com.lww.dao;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import com.lww.util.JsonBaseDao;
import com.lww.util.JsonUtils;
import com.lww.util.PageBean;
import com.lww.util.StringUtils;
public class UserDao extends JsonBaseDao {
/**
* 用户登录或者查询用户分页信息的公共方法
*/
public List
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
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);
}
}
package com.lww.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.fasterxml.jackson.databind.ObjectMapper;
import com.lww.dao.UserDao;
import com.lww.entity.TreeNode;
import com.lww.framework.ActionSupport;
import com.lww.util.ResponseUtil;
public class UserAction extends ActionSupport {
private UserDao userDao = new UserDao();
/**
* 登录成功后跳转index.jsp
*/
public String login(HttpServletRequest req,HttpServletResponse resp) {
// 系统中是否有当前用户
try {
Map
try {
map = this.userDao.list(req.getParameterMap(), null).get(0);
} catch (Exception e) {
req.setAttribute("msg", "用户不存在");
return "login";
}
// 查询用户菜单中间表,获取对应的menuid的集合
if(map != null && map.size() > 0) {
StringBuilder sb = new StringBuilder();
List
for (Map
sb.append(","+m.get("menuId"));
}
req.setAttribute("menuIds", sb.substring(1));
return "index";
}else {
req.setAttribute("msg", "用户不存在");
return "login";
}
} catch (InstantiationException | IllegalAccessException | SQLException e) {
e.printStackTrace();
}
return null;
}
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
$(function(){
$('#tt').tree({
url:'menuAction.action?methodName=menuTree&&Menuid= '+$("#menuIds").val(),
onClick: function(node){
// alert(node.text); 在用户点击的时候提示
// add a new tab panel
var content = '';
if($('#menuTab').tabs('exists',node.text)){
// 存在,执行选项卡选中已有选项卡的操作
$('#menuTab').tabs('select',node.text);
}else{
// 不存在,执行新增的操作
$('#menuTab').tabs('add',{
title:node.text,
content:content,
closable:true
});
}
}
});
})
000用户:
111用户: