修改,查看

dao

package com.likang.dao;

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

import com.likang.entity.TreeNode;
import com.likang.util.JsonBaseDao;
import com.likang.util.JsonUtils;
import com.likang.util.PageBean;
import com.likang.util.StringUtils;

public class MenuDao extends JsonBaseDao{

	
	private List<TreeNode> listTreeNode;
	/**
	 * 给前台返回tree_data1.json的字符串
	 * @param paMap  从前台jsp传递过来的参数集合
	 * @param pageBean
	 * @return
	 * @throws SQLException 
	 * @throws IllegalAccessException 
	 * @throws InstantiationException 
	 */
	public List<TreeNode> listTreeNode(Map<String,String[]> paMap,PageBean pageBean) throws InstantiationException, IllegalAccessException, SQLException{
		
		List<Map<String, Object>> listMap = this.listMapAuth(paMap, pageBean);
		List<TreeNode> listTreeNode=new ArrayList<>();
		this.listMapTOListTreeNode(listMap, listTreeNode);
		return listTreeNode;
		
	}
	
	
	public List<Map<String, Object>> listMap(Map<String,String[]> paMap,PageBean pageBean) throws InstantiationException, IllegalAccessException, SQLException{
		String sql="select *  from t_module where true ";
		String menuId= JsonUtils.getParamVal(paMap, "id");
		if(StringUtils.isNotBlank(menuId)) {
			sql +=" and pid="+menuId;
		}else {
			sql +=" and pid=-1";
		}
		//这里面放的是数据库中的菜单信息
		List<Map<String, Object>> listMap=super.executeQuery(sql, pageBean);
		return listMap;
		
	}
	
	
	public List<Map<String, Object>> listMapAuth(Map<String,String[]> paMap,PageBean pageBean) throws InstantiationException, IllegalAccessException, SQLException{
		String sql="select *  from t_module where true ";
		String menuId= JsonUtils.getParamVal(paMap, "id");
//		为什么将parentid改成menuid?
//		原因在之前的方法中,只能查询当前节点的所有子节点集合,不能将当前节点给查询出来
		if(StringUtils.isNotBlank(menuId)) {
			sql +=" and pid in ("+menuId+")";
		}else {
			sql +=" and pid=-1";
		}
		//这里面放的是数据库中的菜单信息
		List<Map<String, Object>> listMap=super.executeQuery(sql, pageBean);
		return listMap;
		
	}
	/**
	 * [{'Menuid' : 001,'Menuname':'学生管理'},{{‘Menuid’:001,'Menuname':'后勤管理'}}]
	 * -->
	 * {id:...,text:...}
	 * @param map
	 * @param treenode
	 * @throws SQLException 
	 * @throws IllegalAccessException 
	 * @throws InstantiationException 
	 */
	private void mapTOTreeNode(Map<String, Object> map,TreeNode treenode) throws InstantiationException, IllegalAccessException, SQLException {
		treenode.setId(map.get("id")+"");
		treenode.setText(map.get("text")+"");
		treenode.setAttributes(map);
		
//		将子节点添加到父节点当中,建立数据之间的父子关系
//		treenode.setChildren(children);
		Map<String, String[]> childrenMap=new HashMap<>();
		childrenMap.put("id", new String[] {treenode.getId()});
		List<Map<String, Object>> listMap = this.listMap(childrenMap, null);
		List<TreeNode> listTreeNode=new ArrayList<>();
		this.listMapTOListTreeNode(listMap, listTreeNode);
		treenode.setChildren(listTreeNode);
	}
	/**
	 * [{'Menuid' : 001,'Menuname':'学生管理'},{{‘Menuid’:001,'Menuname':'后勤管理'}}]
	 * -->
	 * tree_data1.json
	 * @param listMap
	 * @param listTreeNode
	 * @throws SQLException 
	 * @throws IllegalAccessException 
	 * @throws InstantiationException 
	 */
	private void listMapTOListTreeNode(List<Map<String, Object>> listMap,List<TreeNode> listTreeNode) throws InstantiationException, IllegalAccessException, SQLException {
		TreeNode treeNode=null;
		for (Map<String, Object> map : listMap) {
			treeNode=new TreeNode();
			mapTOTreeNode(map, treeNode);
			listTreeNode.add(treeNode);
		}
	}
	
}

package com.likang.dao;

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

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

public class UserDao extends JsonBaseDao{
/**
 * 用户登录或者查询用户分页信息的公用方法
 * @param paMap
 * @param pageBean
 * @return
 * @throws InstantiationException
 * @throws IllegalAccessException
 * @throws SQLException
 */
	public List<Map<String, Object>> list(Map<String,String[]> paMap,PageBean pageBean) throws InstantiationException, IllegalAccessException, SQLException{
		String sql="select * from t_user where true";
		String uid=JsonUtils.getParamVal(paMap, "user_pingyin");
		String upwd=JsonUtils.getParamVal(paMap, "user_pwd");
		if(StringUtils.isNotBlank(uid)) {
			sql +=" and user_pingyin ="+uid;
		}
		if(StringUtils.isNotBlank(upwd)) {
			sql +=" and user_pwd="+upwd;
					
		}
		return super.executeQuery(sql, pageBean);
	}
	/**
	 * 修改
	 * @param paMap
	 * @return
	 * @throws NoSuchFieldException
	 * @throws SecurityException
	 * @throws IllegalArgumentException
	 * @throws IllegalAccessException
	 * @throws SQLException
	 */
	
	public int update(Map<String,String[]> paMap) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, SQLException {
		String sql="update t_user set user_pingyin=?,user_pwd=?,user_type=? where user_id=? ";
		return super.executeUpdate(sql,new String[] {"user_pingyin","user_pwd","user_type","user_id"} , paMap);
	}
	
	/**
	 * 根据当前用户登录的ID去查询对应的所有菜单
	 * @param paMap
	 * @param pageBean
	 * @return
	 * @throws InstantiationException
	 * @throws IllegalAccessException
	 * @throws SQLException
	 */
	/*public List<Map<String, Object>> getMenuByiUd(Map<String,String[]> paMap,PageBean pageBean) throws InstantiationException, IllegalAccessException, SQLException{
		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);
	}*/
}

action

package com.likang.web;

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

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.likang.dao.MenuDao;
import com.likang.entity.TreeNode;
import com.likang.util.ResponseUtil;
import com.qukang.framework.ActionSupport;

public class MenuAction extends ActionSupport {
	private MenuDao dao=new MenuDao();
	public String menuTree(HttpServletRequest req, HttpServletResponse resp) throws JsonProcessingException, Exception {
		ObjectMapper om= new ObjectMapper();
		//获取到easyui框架所识别的json格式
		List<TreeNode> listTreeNode = this.dao.listTreeNode(req.getParameterMap(), null);
		
		ResponseUtil.write(resp, om.writeValueAsString(listTreeNode));
		return null;
		
	}
}

package com.likang.web;

import java.sql.SQLException;
import java.util.HashMap;
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.likang.dao.UserDao;
import com.likang.util.PageBean;
import com.likang.util.ResponseUtil;
import com.qukang.framework.ActionSupport;

public class UserAction extends ActionSupport{
	private UserDao userDao=new UserDao();
	/**
	 * 登录成功后跳转index.jsp
	 * @param req
	 * @param resp
	 * @return
	 */
/*	public String login(HttpServletRequest req,HttpServletResponse resp) {
//		系统中是否有当前登录用户
		try {
			Map<String, Object> map = this.userDao.list(req.getParameterMap(), null).get(0);
//		有
//		      	查询用户菜单中间表,获取对应menuid的集合
			if(map !=null && map.size()>0) {
				StringBuilder sb=new StringBuilder();
				List<Map<String, Object>> menuIdArr = this.userDao.getMenuByiUd(req.getParameterMap(), null);
				for (Map<String, Object> m : menuIdArr) {
					sb.append(","+m.get("menuId"));
				}
				req.setAttribute("menuIds", sb.substring(1));
				return "index";
				
			}else {
//				没有
				req.setAttribute("msg", "用户不存在");
				return "login";
			}
		} catch (InstantiationException | IllegalAccessException | SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "index";
		
	}*/
public String list(HttpServletRequest req,HttpServletResponse resp) throws InstantiationException, IllegalAccessException, SQLException {
	ObjectMapper om=new ObjectMapper();
	PageBean pageBean=new PageBean();
	pageBean.setRequest(req);
	List<Map<String, Object>> list = this.userDao.list(req.getParameterMap(), pageBean);
	Map<String, Object> map=new HashMap<>();
	map.put("total", pageBean.getTotal());
	map.put("rows", list);
	try {
		ResponseUtil.write(resp, om.writeValueAsString(map));
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return null;
}

public String update(HttpServletRequest req,HttpServletResponse resp) throws InstantiationException, IllegalAccessException, SQLException {
	try {
		int code=this.userDao.update(req.getParameterMap());
		ObjectMapper om=new ObjectMapper();
		Map<String, Object> map=new HashMap<String,Object>();
		map.put("code", code);
		try {
			ResponseUtil.write(resp, om.writeValueAsString(map));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	
	} catch (NoSuchFieldException | SecurityException | IllegalArgumentException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return null;
}

}


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>人员信息管理界面</title>
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/static/js/public/easyui5/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/static/js/public/easyui5/themes/icon.css">
<script type="text/javascript"
	src="${pageContext.request.contextPath }/static/js/public/easyui5/jquery.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/static/js/public/easyui5/jquery.easyui.min.js"></script>


<script type="text/javascript"
	src="${pageContext.request.contextPath }/static/js/userManage.js"></script>
</head>
<body>
	<!-- 展示数据 -->
	<table id="dg"></table>

	<!-- 弹窗 -->
	<div id="dd" class="easyui-dialog" title="编辑窗体"
		style="width: 400px; height: 200px;"
		data-options="iconCls:'icon-save',resizable:true,modal:true,closed:true,buttons:'#bb'">
		<!-- 提交的from表单 -->
		<form id="ff" method="post">
			<input type="hidden" name="user_id">
			<!-- easyui自带正则
	easyui中只是定义了一些常见的正则
	可以在easyui中自定义validTye:'xxx',这个xxx就代表一种正则   
		$.extends({
		validType:xxx
		})
	-->
			
			<div>
				<label for="user_pingyin">name:</label> <input
					class="easyui-validatebox" type="text" name="user_pingyin"
					data-options="required:true" />
			</div>
			<div>
				<label for="user_pwd">pwd:</label> <input class="easyui-validatebox"
					type="text" name="user_pwd" data-options="required:true" />
			</div>
			<div>
				<label for="user_type">权限:</label> <input class="easyui-validatebox"
					type="text" name="user_type" data-options="required:true" />
			</div>

		</form>

		<!-- ctrl+shift+f 格式化 -->

		<!-- </div>  
<div id="tb">
<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true"/a>
<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-help',plain:true"/a>
</div> -->


		<div id="bb">
			<a href="#" class="easyui-linkbutton" onclick="ok()">保存</a> <a
				href="#" class="easyui-linkbutton">关闭</a>
		</div>
</body>
</html>
<%@ 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>后台主界面</title>
<!-- ctrl+shift+r  寻找  -->
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/static/js/public/easyui5/themes/default/easyui.css">   
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/static/js/public/easyui5/themes/icon.css">   
<script type="text/javascript" src="${pageContext.request.contextPath }/static/js/public/easyui5/jquery.min.js"></script>   
<script type="text/javascript" src="${pageContext.request.contextPath }/static/js/public/easyui5/jquery.easyui.min.js"></script>


<script type="text/javascript" src="${pageContext.request.contextPath }/static/js/index.js"></script>

</head>
<body class="easyui-layout">
<input type="hidden" id="menuIds" value="${menuIds }">
	<div data-options="region:'north',border:false" style="height:60px;background:#B3DFDA;padding:10px">north region</div>
	<div data-options="region:'west',split:true,title:'West'" style="width:150px;padding:10px;">
	<ul id="tt"></ul>
	</div>
	<div data-options="region:'east',split:true,collapsed:true,title:'East'" style="width:100px;padding:10px;">east region</div>
	<div data-options="region:'south',border:false" style="height:50px;background:#A9FACD;padding:10px;">south region</div>
	<div data-options="region:'center',title:'Center'">
	<div id="menuTab" class="easyui-tabs" style="">   
    <div title="首页" style="padding:20px;display:none;">   
        欢迎界面    
    </div>   
     
</div>
	</div>
</body>

</html>

js

$(function(){
	$('#tt').tree({    
	    url:'menuAction.action?methodName=menuTree',
	    onClick: function(node){
	    
	    	// add a new tab panel
	    	
	    	var content = '<iframe scrolling="no" frameborder="0"    src="'+node.attributes.url+'" width="1600" height="800"></iframe>';
	    	if($('#menuTab').tabs('exists',node.text)){
	    		//存在执行选项卡选中已有选项卡的操作
	    		$('#menuTab').tabs('select',node.text);
	    	}else{
	    		//不存在执行新增的操作
	    		$('#menuTab').tabs('add',{    
		    	    title:node.text,    
		    	    content:content,    
		    	    closable:true,
		    	    fit:true,
		    	    height:15,
		    	    
		    	   
		    	}); 
	    	}
	    	
	    	
	    }
	});
	
})
function add(){
	
}
$(function() {
	$('#dg').datagrid({    
	    url:'../userAction.action?methodName=list',
//	    行填充
	    fit:true,
//	    列填充
	    fitColumns:true,
//	   分页条
	    pagination:true,
//	    如果为true,则只允许选择一行。
	    singleSelect:true,
	    columns:[[    
	    
	        {field:'user_pingyin',title:'名称',width:100}, 
	        {field:'user_type',title:'权限',width:100},
	        {field:'user_pwd',title:'密码',width:100,align:'right'}    
	    ]],
	    toolbar: [{
//	    	增加
			iconCls: 'icon-add',
			handler: function(){
				$('#dd').dialog('open')
				}
		},'-',{
			iconCls: 'icon-edit',
//			修改
			handler: function(){
				$('#dd').dialog('open')
				var row =$('#dg').datagrid('getSelected');
				if(row){
					$('#ff').form('load',row);
				}
			}
		},'-',{
//			删除
			iconCls: 'icon-remove',
			handler: function(){alert('移除按钮')}
		}]

	});
	
})

function ok() {
	alert('ok');
	$('#ff').form('submit', {    
	    url:'../userAction.action?methodName=update',    
	    success:function(data){
//	        alert(data); 
	    	$('#ff').form('clear');
	    	$('#dd').dialog('close');
	    	$('#dg').datagrid('reload');
	    }    
	});
}

结果如下
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
好了,就展示到这吧,
项目还没有写完

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值