ui框架

1、需要导入的所有jar包,以及外部的类或文件

1.1导入jar包

1.2导入WebContent外部资源

1.3导入所有需要的辅助类--Util包

2.实例代码

2.1创建TreeNode实体类

public class TreeNode {
private String id;
private String text;
private List<TreeNode> children=new ArrayList<TreeNode>();
private Map<String, Object> attributes=new HashMap<String, Object>(); public String getId() {
return id;
} public void setId(String id) {
this.id = id;
} public String getText() {
return text;
} public void setText(String text) {
this.text = text;
} public List<TreeNode> getChildren() {
return children;
} public void setChildren(List<TreeNode> children) {
this.children = children;
} public Map<String, Object> getAttributes() {
return attributes;
} public void setAttributes(Map<String, Object> attributes) {
this.attributes = attributes;
} @Override
public String toString() {
return "TreeNode [id=" + id + ", text=" + text + ", children=" + children + ", attributes=" + attributes + "]";
} }

2.2dao层--MenuDao

 package com.yuan.dao;

 import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import com.yuan.entity.TreeNode;
import com.yuan.util.JsonBaseDao;
import com.yuan.util.JsonUtils;
import com.yuan.util.PageBean;
import com.yuan.util.StringUtils; public class MenuDao extends JsonBaseDao { /**
* 给前台tree_data1_json的字符串
* @param paMap 从前台jsp传递过来的参数集合
* @param pageBean
* @return
* @throws InstantiationException
* @throws IllegalAccessException
* @throws SQLException
*/
public List<TreeNode> listTreeNode(Map<String, String[]> paMap,PageBean pageBean) throws InstantiationException, IllegalAccessException, SQLException{
List<Map<String, Object>> listMap = this.listMap(paMap, pageBean);
List<TreeNode> listTreeNode=new ArrayList<TreeNode>();
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_easyui_menu WHERE TRUE";
String menuId=JsonUtils.getParamVal(paMap, "Menuid");
if(StringUtils.isNotBlank(menuId)) {
sql+=" AND parentid="+menuId;
}
else {
sql+=" AND parentid=-1";
} //这里面存放数据库中的菜单信息
List<Map<String, Object>> listMap = super.executeQuery(sql, pageBean);
return listMap;
} /**
* {'Menuid':001,'Menuame':'学生管理'}
* {id:..,text:...}
* @param map
* @param treeNode
* @throws InstantiationException
* @throws IllegalAccessException
* @throws SQLException
*/
private void MapToTreeNode(Map<String, Object> map,TreeNode treeNode) throws InstantiationException, IllegalAccessException, SQLException {
treeNode.setId(map.get("Menuid")+"");
treeNode.setText(map.get("Menuname")+"");
treeNode.setAttributes(map); // 将子节点添加到父节点当中,建立数据之间的父子关系
// treeNode.setChildren(children);
Map<String, String[]> childrenMap=new HashMap<>();
childrenMap.put("Menuid", 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,'Menuame':'学生管理'},{'Menuid':002,'Menuame':'后勤管理'}]
* @param listMap
* tree_data1_json
* @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);
} } }

2.3web层--MenuAction

 package com.yuan.web;

 import java.util.List;

 import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import com.fasterxml.jackson.databind.ObjectMapper;
import com.yuan.dao.MenuDao;
import com.yuan.entity.TreeNode;
import com.yuan.util.ResponseUtil;
import com.***.framework.ActionSupport; public class MenuAction extends ActionSupport{ private MenuDao menuDao=new MenuDao(); public String menuTree(HttpServletRequest request,HttpServletResponse response) throws Exception {
ObjectMapper om=new ObjectMapper();
//获取到 easyui所识别的json格式
List<TreeNode> listTreeNode = this.menuDao.listTreeNode(request.getParameterMap(), null);
ResponseUtil.write(response, om.writeValueAsString(listTreeNode)); return null;
} }

2.4 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>
<!-- Ctrl+Shift+r -->
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/js/public/easyui5/themes/default/easyui.css"> <!-- 引入easyui样式文件-->
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/js/public/easyui5/themes/icon.css"> <!-- 引入easyui图标样式文件-->
<script type="text/javascript" src="${pageContext.request.contextPath}/static/js/public/easyui5/jquery.min.js"></script> <!-- 引入jQuery -->
<script type="text/javascript" src="${pageContext.request.contextPath}/static/js/public/easyui5/jquery.easyui.min.js"></script> <!-- 引入easyui-->
<script type="text/javascript" src="${pageContext.request.contextPath}/static/js/index.js"></script> </head>
<body class="easyui-layout">
<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>

2.5 xml配置

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>easyui01</display-name>
<filter>
<filter-name>encodingFiter</filter-name>
<filter-class>com.yuan.util.EncodingFiter</filter-class>
</filter>
<filter-mapping>
<filter-name>encodingFiter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <servlet>
<servlet-name>actionServlet</servlet-name>
<servlet-class>com.***.framework.ActionServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>actionServlet</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
</web-app>

mvc.xml

<?xml version="1.0" encoding="UTF-8"?>
<config> <action path="/menuAction" type="com.yuan.web.MenuAction">
</action> </config>

2.6数据库信息 (展示部分)

2.7显示结果

谢谢观看^-^ !!!

easyUI--入门实例的更多相关文章

  1. React 入门实例教程(转载)

    本人转载自: React 入门实例教程

  2. struts入门实例

    入门实例 1  .下载struts-2.3.16.3-all  .不摆了.看哈就会下载了. 2  . 解压  后 找到 apps 文件夹. 3.    打开后将 struts2-blank.war   ...

  3. Vue.js2.0从入门到放弃---入门实例

    最近,vue.js越来越火.在这样的大浪潮下,我也开始进入vue的学习行列中,在网上也搜了很多教程,按着教程来做,也总会出现这样那样的问题(坑啊,由于网上那些教程都是Vue.js 1.x版本的,现在用 ...

  4. wxPython中文教程入门实例

    这篇文章主要为大家分享下python编程中有关wxPython的中文教程,分享一些wxPython入门实例,有需要的朋友参考下     wxPython中文教程入门实例 wx.Window 是一个基类 ...

  5. Omnet++ 4.0 入门实例教程

    http://blog.sina.com.cn/s/blog_8a2bb17d01018npf.html 在网上找到的一个讲解omnet++的实例, 是4.0下面实现的. 我在4.2上试了试,可以用. ...

  6. Spring中IoC的入门实例

    Spring中IoC的入门实例 Spring的模块化是很强的,各个功能模块都是独立的,我们可以选择的使用.这一章先从Spring的IoC开始.所谓IoC就是一个用XML来定义生成对象的模式,我们看看如 ...

  7. Node.js入门实例程序

    在使用Node.js创建实际“Hello, World!”应用程序之前,让我们看看Node.js的应用程序的部分.Node.js应用程序由以下三个重要组成部分: 导入需要模块: 我们使用require ...

  8. Java AIO 入门实例(转)

    Java7 AIO入门实例,首先是服务端实现: 服务端代码 SimpleServer: public class SimpleServer { public SimpleServer(int port ...

  9. Akka入门实例

    Akka入门实例 Akka 是一个用 Scala 编写的库,用于简化编写容错的.高可伸缩性的 Java 和 Scala 的 Actor 模型应用. Actor模型并非什么新鲜事物,它由Carl Hew ...

  10. Asp.Net MVC2.0 Url 路由入门---实例篇

    本篇主要讲述Routing组件的作用,以及举几个实例来学习Asp.Net MVC2.0 Url路由技术. 接着上一篇开始讲,我们在Global.asax中注册一条路由后,我们的请求是怎么转到相应的Vi ...

随机推荐

  1. ASP.NET Core四大部件

    四大部件 (WebHost,Startup,launchSettings,wwwroot) WebHost 简单理解是一个socket, https://www.cnblogs.com/neverc/ ...

  2. Java基础笔试练习(三)

    1.下列InputStream类中哪个方法可以用于关闭流? A.skip() B.close() C.mark() D.reset() 答案: B 解析: inputstream的close方法用来关 ...

  3. ansible使用普通用户免密登陆+sudo提权

    前提:从ansible控制端使用test用户可以免密登陆所有被控制端,并且被控端test用户支持sudo提权 # ansible主机清单 cat /etc/ansible/hosts [online- ...

  4. C++进行字母大小写转换

    #include <iostream> #include <Windows.h> #include <string> using namespace std; in ...

  5. WSL部署记录

    1. 管理员打开PowerShell,开启WSL功能: Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Sub ...

  6. SAS学习笔记54 RTF文件格式

    Style RTF Control Word Example Code Italicize \i title '\i italicized title'; Underline \ul title '\ ...

  7. Java QuickSelect

    Java QuickSelect /** * <html> * <body> * <P> Copyright 1994-2018 JasonInternationa ...

  8. python练习:异常

    异常习题: 一 编写with操作类Fileinfo(),定义__enter__和__exit__方法.完成功能: 1.1 在__enter__方法里打开Fileinfo(filename),并且返回f ...

  9. SQL Server2008本地数据库调用SP发送邮件

    一.首先要对本地数据库做配置 1.通过使用数据库邮件配置向导和sp_configure存储过程配置启用数据库邮件: 注:服务器名称填写发送服务器的路径或者IP,电子邮件地址为寄件者地址 配置好数据库邮 ...

  10. .net core使用CSRedisCore连接哨兵集群,并用作redis使用分布式缓存。

    CSRedisCore是国内大佬出品的一个Redis-Cli-SDK. Github地址:https://github.com/2881099/csredis 使用此插件作为分布式缓存也十分简单. 一 ...