欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

easyui入门

程序员文章站 2022-03-30 19:15:17
...

EasyUI入门

1.EasyUI是什么?

jQuery EasyUI是一组基于jQuery的UI插件集合体,而jQuery EasyUI的目标就是帮助web开发者更轻松的打造出功能丰富并且美观的UI界面。开发者不需要编写复杂的javascript,也不需要对css样式有深入的了解,开发者需要了解的只有一些简单的html代码

2.jQuery EasyUI有以下特点:

1、基于jquery用户界面插件的集合
2、为一些当前用于交互的js应用提供必要的功能
3、EasyUI支持两种渲染方式分别为javascript方式(如:$(’#p’).panel({…}))和html标记方式(如:class=“easyui-panel”)
4、支持HTML5(通过data-options属性)
5、开发产品时可节省时间和资源
6、简单,但很强大
7、支持扩展,可根据自己的需求扩展控件
8、目前各项不足正以版本递增的方式不断完善

3.代码实现案例

easyui入门
需要导入的jar包:
easyui入门
util工具类:

easyui入门

引入js和css样式文件

<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>  

3.1通过layout布局:

<%@ 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>  
</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>

easyui入门

MenuDao.java

package com.pyc.dao;

import java.sql.SQLException;

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

import com.pyc.entity.TreeNode;

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



public class MenuDao extends JsonBaseDao {
	/**
	 * * 给前台返回tree_data1.json的字符串
	 *   从前台jsp传递过来的参数集合
	 * List<TreeNode>加上ObjectMapper可以转换成easyui的tree控件识别的json串
	 * @param map
	 * @param pageBean
	 * @return
	 * @throws SQLException 
	 * @throws IllegalAccessException 
	 * @throws InstantiationException 
	 */
	public List<TreeNode> listTreeNode(Map<String, String[]> map, PageBean pageBean) throws InstantiationException, IllegalAccessException, SQLException{
		List<Map<String, Object>> listMenu = this.listMenu(map, pageBean);
		List<TreeNode> listTreeNode = new ArrayList<TreeNode>();
		this.listMapToListTreeNode(listMenu, listTreeNode);
		return listTreeNode;
	}
	
	/**
	 * List<Map<String,Object>>
	 * ->【{Menuid:001,Menuname:学生管理,children:[]},{Menuid:001,Menuname:学生管理}】
	 * 	接下来需要递归查询子节点的集合存入当前节点
	 * 	
	 * @param map
	 * @param pageBean
	 * @return
	 * @throws InstantiationException
	 * @throws IllegalAccessException
	 * @throws SQLException
	 */
	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 ";
		String id = JsonUtils.getParamVal(map, "Menuid");
		//System.out.println("id:"+id);
		if(StringUtils.isNotBlank(id)) {
//			当前节点的ID当作子节点父ID进行查询
			sql += " and parentid="+id;
			//System.out.println(sql);
		}else {
			sql += " and parentid=-1";
			//System.out.println(sql);
		}
		return super.executeQuery(sql, pageBean);
	}
	
	/**
	 * 需要将后台数据库查出来的数据格式转换成前台easyui所识别的数据
	 * @param map
	 * @param treeNode
	 * @throws SQLException 
	 * @throws IllegalAccessException 
	 * @throws InstantiationException 
	 */
	public void mapToTreeNode(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[]> childMap = new HashMap<String, String[]>();
		childMap.put("Menuid", new String[] {treeNode.getId()});
//		查询出当前节点所拥有的子节点的集合
		List<Map<String, Object>> listMenu = this.listMenu(childMap, null);
		List<TreeNode> listTreeNode = new ArrayList<TreeNode>();
		this.listMapToListTreeNode(listMenu, listTreeNode);
		treeNode.setChildren(listTreeNode);
	}
	
	public void listMapToListTreeNode(List<Map<String, Object>> list, List<TreeNode> listTreeNode) throws InstantiationException, IllegalAccessException, SQLException {
		TreeNode treeNode = null;
		for (Map<String, Object> map : list) {
			treeNode = new TreeNode();
			this.mapToTreeNode(map, treeNode);
			listTreeNode.add(treeNode);
		}
	}
}

TreeNode.java

package com.pyc.entity;

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

/**
 * 针对easyui属性展示的json格式串进行了实体类的描述
 * @author 96345
 *
 */
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 + "]";
	}
	
	
}

MenuAction.java

package com.pyc.web;

import java.sql.SQLException;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.pyc.dao.MenuDao;
import com.pyc.entity.TreeNode;
import com.pyc.framework.ActionSupport;

import util.ResponseUtil;

public class MenuAction extends  ActionSupport{
	private MenuDao menuDao = new MenuDao();

	public String menuTree(HttpServletRequest req,HttpServletResponse resp) {
		try {
			List<TreeNode> listTreeNode = this.menuDao.listTreeNode(req.getParameterMap(), null);
			ObjectMapper om = new ObjectMapper();
			ResponseUtil.write(resp, om.writeValueAsString(listTreeNode));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}

index.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">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/easyui/themes/default/easyui.css">   
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/easyui/themes/icon.css">   
<script type="text/javascript" src="${pageContext.request.contextPath}/static/easyui/jquery.min.js"></script>   
<script type="text/javascript" src="${pageContext.request.contextPath}/static/easyui/jquery.easyui.min.js"></script>  
<script type="text/javascript" src="${pageContext.request.contextPath}/static/js/index.js"></script>  
<title>后台管理主界面</title>
</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="height: 800px;">   
    <div title="首页" style="padding:20px;display:none;">   
        默认首页展示内容    
    </div>   
</div>  
	</div>
</body>
</html>

easyui入门

相关标签: easyui