Easyui(一)

Easyui(一)

1:什么是Easyui

EasyUI的目标就是帮助web开发者更轻松的打造出功能丰富并且美观的UI界面。
开发者不需要编写复杂的avascript,也不需要对css样式有深入的了解,
开发者需要了解的只有一些简单的html标签。

2:市面上的UI标签有哪些呢?

easyui:基本上的功能都有 但是页面不美观,不支持响应式
bootstrap:页面美观 需要收费 支持响应式
layui:页面美观 但是本身自带bug 支持响应式

案例
layout布局
tree加载菜单
tabs

引入easyui

如何引用呢
步骤如下:1:首先我们先把官网上写的代码copy到页面上
2:点中/static的后面一窜代码
3:选中Ctrl+Shift+R 点击最后含有default结尾的
4:点击黄色的交换的这个
在这里插入图片描述
5:选中Copy Qualifed Name 点击 再把官网上的值替换 就可以了

<link rel="stylesheet" type="text/css" href="easyui/themes/default/easyui.css">   
<link rel="stylesheet" type="text/css" href="easyui/themes/icon.css">   
<script type="text/javascript" src="easyui/jquery-1.7.2.min.js"></script>   
<script type="text/javascript" src="easyui/jquery.easyui.min.js"></script> 

官网代码与自定义代码的定义

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/static/js/easyui5/themes/default/easyui.css">   
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/static/js/easyui5/themes/icon.css">   
<script type="text/javascript" src="${pageContext.request.contextPath }/static/js/easyui5/jquery.min.js"></script>   
<script type="text/javascript" src="${pageContext.request.contextPath }/static/js/easyui5/jquery.easyui.min.js"></script>  

注意:顺序不能乱,因为一个路径是倚靠另外一个路径而展现出来的

今天我们的 案例

[{
	"id":1,
	"text":"My Documents",
	"children":[{
		"id":11,
		"text":"Photos",
		"state":"closed",
		"children":[{
			"id":111,
			"text":"Friend"
		},{
			"id":112,
			"text":"Wife"
		},{
			"id":113,
			"text":"Company"
		}]
	},{
		"id":12,
		"text":"Program Files",
		"children":[{
			"id":121,
			"text":"Intel"
		},{
			"id":122,
			"text":"Java",
			"attributes":{
				"p1":"Custom Attribute1",
				"p2":"Custom Attribute2"
			}
		},{
			"id":123,
			"text":"Microsoft Office"
		},{
			"id":124,
			"text":"Games",
			"checked":true
		}]
	},{
		"id":13,
		"text":"index.html"
	},{
		"id":14,
		"text":"about.html"
	},{
		"id":15,
		"text":"welcome.html"
	}]
}]

//实体类更具案例里面的值来定义

实体类:

public class TreeNode {
		private String id;
		private String text;
		private List<TreeNode> children=new ArrayList<>();
		private Map<String, Object> attributes=new HashMap<>();
		
		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 + "]";
		}
	}

我们所需要引入的类
在这里插入图片描述
架包:
在这里插入图片描述

index页面

    <%@ 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">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/static/js/easyui5/themes/default/easyui.css">   
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/static/js/easyui5/themes/icon.css">   
    <script type="text/javascript" src="${pageContext.request.contextPath }/static/js/easyui5/jquery.min.js"></script>   
    <script type="text/javascript" src="${pageContext.request.contextPath }/static/js/easyui5/jquery.easyui.min.js"></script>  
    
    <title>Insert title here</title>
    </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;">west content</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>
    </body>
    </html>
    ```

    
    
    
 注意:不要少写或者是漏写路径名



通过tree加载菜单
MenuDao 继承了JsonBaseDao

public class MenuDao extends JsonBaseDao {
   /**
	 * @param map  req.getparamerMap
	 * @param pageBean 分页
	 * @return
	 * @throws SQLException 
	 * @throws IllegalAccessException 
	 * @throws InstantiationException 
	 */
		public List<TreeNode> list(Map<String, String[]> map,PageBean pageBean) throws InstantiationException, IllegalAccessException, SQLException{
			List<Map<String,Object>> listMenu = this.listMenu(map, pageBean);
			List<TreeNode> treeNodeList=new ArrayList<>();
			menuList2TreeNodeList(listMenu, treeNodeList);
			return treeNodeList;
		
	}
	
	/**
	 * 1.查询menu表的数据
	 * @param map 
	 * @param pageBean
	 * @return
	 * @throws SQLException 
	 * @throws IllegalAccessException 
	 * @throws InstantiationException 
	 */
	//查询不一定要对象 ,也可以集合  Map<String,Object>
		public List<Map<String,Object>> listMenu(Map<String, String[]> map,PageBean pageBean) throws InstantiationException, IllegalAccessException, SQLException{
			//数据库的列名与我们写的不同  所有需要查询
			String sql="select * from t_easyui_menu where true ";
			//拿到当前节点的Id  id把ID当成父Id来查
			String id=JsonUtils.getParamVal(map, "id");
			//子节点由父Id来传
			if(StringUtils.isNotBlank(id)) {
				sql = sql + " and parentid = "+id;
			}else {
				//根节点数据库为负一
				sql = sql + " and parentid = -1";
			}
			//查询所有节点
			return super.executeQuery(sql, pageBean);
		}
	
	/**
	 * {Means:1,....[]}
	 * -->{id:1,....[]}
	 * menu表的数据格式不符合easyui树形展示的数据格式
	 * 需要转化成easyui所识别的数据格式
	 * @param map
	 * @param treeNode
	 * @throws SQLException 
	 * @throws IllegalAccessException 
	 * @throws InstantiationException 
	 */
	private  void  menu2TreeNode(Map<String, Object>map,TreeNode treeNode) throws InstantiationException, IllegalAccessException, SQLException {
			treeNode.setId(map.get("Menuid").toString());
			treeNode.setText(map.get("Menuname").toString());
			treeNode.setAttributes(map);
	
			//		treeNode.setChildren(children);
			Map<String, String[]> jspMap=new HashMap<>();
			//当前节点作为父节点的id查
			jspMap.put("id", new String[] {treeNode.getId()});
			//查出当前Id的子节点  直接查找数据库
			List<Map<String, Object>> listMenu = this.listMenu(jspMap, null);
			//转换为TreeNode
			List<TreeNode> treeNodeList=new ArrayList<>();
			menuList2TreeNodeList(listMenu, treeNodeList);
			treeNode.setChildren(treeNodeList);
			
		}
			
	
		
		/**
		 * [{Means:1,....[]},{Means:2,....[]}]
		 * -->[{id:1,....[]},{id:2,....[]}]
		 * @param mapList
		 * @param treeNodeList
		 * @throws InstantiationException
		 * @throws IllegalAccessException
		 * @throws SQLException
		 */
		private  void  menuList2TreeNodeList(List<Map<String, Object>>mapList,List<TreeNode> treeNodeList) throws InstantiationException, IllegalAccessException, SQLException {
			//节约内存
			TreeNode treeNode=null;
			for (Map<String, Object> map : mapList) {
				treeNode=new TreeNode();
				menu2TreeNode(map, treeNode);
				treeNodeList.add(treeNode);
			}
		}
	}

mvc.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
	<action path="/menuAction" type="com.xyx.web.MenuAction">
		<forward name="index" path="/index.jsp" redirect="false" />
	</action>
</config>

MenuAction

public class MenuAction extends ActionSupport {
	private MenuDao menuDao=new MenuDao();
	public String treeMenu(HttpServletRequest req,HttpServletResponse resp) {
		try {
			List<TreeNode> list = this.menuDao.list(req.getParameterMap(), null);
			//将list集合转换为json串
			ObjectMapper om=new ObjectMapper();
			String jsonStr = om.writeValueAsString(list);
			ResponseUtil.write(resp, jsonStr);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
		
	}

}


tabs
tabs菜单页面,在左侧会出现相应的操作

//写一个程序入口:
$(function(){
	$('#tt').tree({    
	    url:'menuAction.action?methodName=treeMenu',
	    onClick:function(node){
	    	var content = '<iframe scrolling="no" frameborder="0" src="'+node.attributes.menuURL+'" width="99%" height="99%"></iframe>';
	    	if($('#menuTabs').tabs('exists',node.text)){
	    		$('#menuTabs').tabs('select',node.text);
	    	}else{
	    		$('#menuTabs').tabs('add',{    
	    			title:node.text,    
	    			content:content,    
	    			closable:true,    
	    			tools:[{    
	    				iconCls:'icon-mini-refresh',    
	    				handler:function(){    
	    					alert('refresh');    
	    				}    
	    			}]    
	    		}); 
	    		
	    	}
	    }
	});  
})

//页面的展示为:
在这里插入图片描述

//页面点击展示的效果:
在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值