EasyUi (三)

本文详细介绍了如何在前端实现树状结构展示数据库表数据,特别聚焦于使用EasyUI组件展示t_easyui_menu表。同时,针对Tomcat高版本中因URL参数编码问题导致的错误,提供了三种解决方案,包括修改Tomcat配置、更换Tomcat版本及参数编码。

前言

昨天学习了树(tree)形结构
今天来把数据库的表实现到页面上

完成目标
在这里插入图片描述
今天写的时候还遇到个错误

在请求目标中发现无效字符。有效字符在RFC 7230和RFC 3986中定义

在这里插入图片描述
然后百度了下发现这个问题是高版本tomcat中的新特性:就是严格按照 RFC 3986规范进行访问解析,而 RFC 3986规范定义了Url中只允许包含英文字母(a-zA-Z)、数字(0-9)、-_.~4个特殊字符以及所有保留字符(RFC3986中指定了以下字符为保留字符:! * ’ ( ) ; : @ & = + $ , / ? # [ ])。而我们的系统在通过地址传参时,在url中传了一段json,传入的参数中有”{“不在RFC3986中的保留字段中,所以会报这个错。

这里有三种解决方法 我用的第一种

  1. 编辑Tomcat /config/catalina.properties 配置文件,找到 tomcat.util.http.parser.HttpParser.requestTargetAllow=|,解开注释,并配置tomcat.util.http.parser.HttpParser.requestTargetAllow=|{}。(此属性只支持| { } 三种字符)。

在这里插入图片描述
在这里插入图片描述
解决办法2:

最轻便的方法,更换tomcat版本。此方法比较快。

解决办法3:

对相应的参数进行编码,就是将所有的参数都进行编码

-----------参考文章-------------

------------参考文章------------

实现

要实现页面我们要写dao方法 写dao方法要继承basedao 我们需要mvc的架包

首先导入mvc的架包 再把配置文件conf 和下面的mvc.xml也C过来

在这里插入图片描述
在这里插入图片描述

然后写dao方法

package com.zhuchenxi.dao;

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

import com.fasterxml.jackson.databind.ObjectMapper;
import com.zhuchenxi.entity.Permission;
import com.zhuchenxi.util.BaseDao;
import com.zhuchenxi.util.BuildTree;
import com.zhuchenxi.util.PageBean;
import com.zhuchenxi.vo.TreeVo;

public class PermissionDao extends BaseDao<Permission> {

	/**
	 * 
	 * 是直接从数据库获取到的数据
	 * @param permission
	 * @param pageBean
	 * @return
	 * @throws Exception
	 */
	public List<Permission> list(Permission permission,PageBean pageBean) throws Exception {
		
		String sql="select * from t_easyui_Permission";
		return super.executeQuery(sql, Permission.class, pageBean);
	}
	
	/**
	 * 能够将数据库中的数据,体现夫子结构
	 * @param permission
	 * @param pageBean
	 * @return
	 * @throws Exception
	 */
//	public TreeVo<Permission> topNode(Permission permission,PageBean pageBean) throws Exception {
//		
//		List<Permission> list = this.list(permission, pageBean);
//
//		List<TreeVo<Permission>> nodes = new ArrayList<TreeVo<Permission>>();
//
//		TreeVo treeVo = null;
//		
//		for (Permission p : list) {
//			treeVo = new TreeVo<>();
//			treeVo.setId(p.getId()+"");
//			treeVo.setText(p.getName());
//			treeVo.setParentId(p.getPid()+"");
//			Map<String, Object> attributes = new HashMap<String, Object>();
//			attributes.put("self", p);
//			treeVo.setAttributes(attributes);
//			nodes.add(treeVo);
//		}
//		
//		return BuildTree.build(nodes);
//		
//	}
	public List<TreeVo<Permission>> topNode(Permission permission,PageBean pageBean) throws Exception {
	
		List<Permission> list = this.list(permission, pageBean);
	
		List<TreeVo<Permission>> nodes = new ArrayList<TreeVo<Permission>>();
	
		TreeVo treeVo = null;
		
		for (Permission p : list) {
			treeVo = new TreeVo<>();
			treeVo.setId(p.getId()+"");
			treeVo.setText(p.getName());
			treeVo.setParentId(p.getPid()+"");
			Map<String, Object> attributes = new HashMap<String, Object>();
			attributes.put("self", p);
			treeVo.setAttributes(attributes);
			nodes.add(treeVo);
		}
		
		return BuildTree.buildList(nodes,"0");
	
	}
	
	
	public static void main(String[] args) throws Exception {
		PermissionDao pd = new PermissionDao();
		List<Permission> list = pd.list(null, null);
		
//		通过工具类完成指定格式的输出
		List<TreeVo<Permission>> nodes = new ArrayList<TreeVo<Permission>>();
//		Permission的格式不满足easyui的tree组件的展现的数据格式的
//		将List<Permission>转换成<TreeVo<T>>
//		实现,将List<Permission>得到的单个permission转成TreeVo,将Treev加入到nodes
		
		TreeVo treeVo = null;
		
		for (Permission p : list) {
			treeVo = new TreeVo<>();
			treeVo.setId(p.getId()+"");
			treeVo.setText(p.getName());
			treeVo.setParentId(p.getPid()+"");
//			Map<String, Object> attributes = new HashMap<String, Object>();
//			attributes.put("self", p);
//			treeVo.setAttributes(attributes);
			nodes.add(treeVo);
		}
		
		TreeVo<Permission> parent = BuildTree.build(nodes);
		ObjectMapper om = new ObjectMapper();
		String jsonstr = om.writeValueAsString(parent);
		System.out.println(jsonstr);
		
	}
}

这里面的topNode是来自于辅助类BuildTree String idParam 就是顶级节点需要什么传什么

在这里插入图片描述

然后配置在中央控制器里面

package com.zhuchenxi.web;

import java.util.ArrayList;
import java.util.List;

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

import com.zhuchenxi.dao.PermissionDao;
import com.zhuchenxi.entity.Permission;
import com.zhuchenxi.framework.ActionSupport;
import com.zhuchenxi.framework.ModelDriven;
import com.zhuchenxi.util.PageBean;
import com.zhuchenxi.vo.TreeVo;
import com.zhuchenxi.util.ResponseUtil;

public class PermissionAction extends ActionSupport implements ModelDriven<Permission>{

	private Permission ps = new Permission();
	private PermissionDao pd = new PermissionDao();
	
	@Override
	public Permission getModel() {
		// TODO Auto-generated method stub
		return ps;
	}
	
	public String menuTree(HttpServletRequest req,HttpServletResponse resp) {
		try {
//			TreeVo<Permission> topNode = this.pd.topNode(null, null);
//			List<TreeVo<Permission>> list = new ArrayList<TreeVo<Permission>>();
//			list.add(topNode);
			ResponseUtil.writeJson(resp, this.pd.topNode(null, null));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	
}

在配置路徑

<action path="/permission" type="com.zhuchenxi.web.PermissionAction">
		<!-- <forward name="index" path="/index.jsp" redirect="false" /> -->
	</action>

在主界面上写上input 配置在index.js里面
在这里插入图片描述
在这里插入图片描述

完成效果

在这里插入图片描述

实现 t_easyui_menu 表

照搬就行啦

昨天写过的 就不写实体类了 直接改dao方法

package com.zhuchenxi.dao;

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

import com.fasterxml.jackson.databind.ObjectMapper;
import com.zhuchenxi.entity.Menu;
import com.zhuchenxi.entity.Permission;
import com.zhuchenxi.util.BaseDao;
import com.zhuchenxi.util.BuildTree;
import com.zhuchenxi.util.PageBean;
import com.zhuchenxi.vo.TreeVo;

public class MenuDao extends BaseDao<Menu>{

	public List<Menu> list(Menu menu,PageBean pageBean) throws Exception {
		String sql="select * from t_easyui_menu where true";
		return super.executeQuery(sql, Menu.class, pageBean);
	}
	
	
	public List<TreeVo<Menu>> topNode(Menu menu,PageBean pageBean) throws Exception {
		
		List<Menu> list = this.list(menu, pageBean);
	
		List<TreeVo<Menu>> nodes = new ArrayList<TreeVo<Menu>>();
	
		TreeVo treeVo = null;
		
		for (Menu p : list) {
			treeVo = new TreeVo<>();
			treeVo.setId(p.getMenuid());
			treeVo.setText(p.getMenuname());
			treeVo.setParentId(p.getParentid());
			Map<String, Object> attributes = new HashMap<String, Object>();
			attributes.put("self", p);
			treeVo.setAttributes(attributes);
			nodes.add(treeVo);
		}
		
		return BuildTree.buildList(nodes,"-1");
	
	}
	
	
	
	
	
	
	public static void main(String[] args) throws Exception {
		MenuDao md = new MenuDao();
		List<Menu> list = md.list(null, null);
		
//		通锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟街革拷锟斤拷锟绞斤拷锟斤拷锟斤拷
		List<TreeVo<Menu>> nodes = new ArrayList<TreeVo<Menu>>();
		
		TreeVo treeVo = null;
		
		for (Menu p : list) {
			treeVo = new TreeVo<>();
			treeVo.setId(p.getMenuid());
			treeVo.setText(p.getMenuname());
			treeVo.setParentId(p.getParentid());
//			Map<String, Object> attributes = new HashMap<String, Object>();
//			attributes.put("self", p);
//			treeVo.setAttributes(attributes);
			nodes.add(treeVo);
		}
		
		TreeVo<Menu> parent = BuildTree.build(nodes);
		ObjectMapper om = new ObjectMapper();
		String jsonstr = om.writeValueAsString(parent);
		System.out.println(jsonstr);
		
		
		
	}
	
}

配置中央控制器

package com.zhuchenxi.web;

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

import com.zhuchenxi.dao.MenuDao;
import com.zhuchenxi.entity.Menu;
import com.zhuchenxi.framework.ActionSupport;
import com.zhuchenxi.framework.ModelDriven;
import com.zhuchenxi.util.ResponseUtil;

public class MenuAction extends ActionSupport implements ModelDriven<Menu> {

	private  Menu menu = new Menu();
	private  MenuDao md =   new MenuDao();

	@Override
	public Menu getModel() {
		// TODO Auto-generated method stub
		return menu;
	}
	
	
	public String menuTree(HttpServletRequest req,HttpServletResponse resp) {
		try {
//			TreeVo<Permission> topNode = this.pd.topNode(null, null);
//			List<TreeVo<Permission>> list = new ArrayList<TreeVo<Permission>>();
//			list.add(topNode);
			ResponseUtil.writeJson(resp, this.md.topNode(null, null));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

}

重点来了 因为在dao方法里调的buidList方法 在index.js里面改下路径 就可以显示页面了 超级方便
在这里插入图片描述

在这里插入图片描述

效果图

在这里插入图片描述

现在思路越来越好了 很高兴 希望能保持下去~~

内容概要:本文围绕可变桨叶四旋翼无人机的规范控制与点对点运动模拟展开,重点研究优化推力分配策略在翻转动作中的应用与性能比较。通过Matlab代码实现,构建了四旋翼动力学模型,并设计了多种控制算法以实现精确的姿态调整与轨迹跟踪。研究对比了不同推力分配方案在执行高机动性翻转动作时的稳定性、能耗效率与响应速度,旨在提升无人机在复杂飞行任务中的动态性能与控制精度。该仿真研究为无人机飞控系统的设计与优化提供了理论依据和技术支持。; 适合人群:具备一定自动控制理论基础和Matlab编程能力,从事无人机控制、飞行器动力学或机器人系统研究的科研人员及研究生。; 使用场景及目标:① 实现四旋翼无人机在三维空间中的精确点对点运动控制;② 对比分析不同推力分配策略在执行翻转等高难度动作时的控制效果与能耗表现,优化飞行性能;③ 为无人机自主飞行、特技飞行及复杂环境下的机动控制提供算法验证平台。; 阅读建议:此资源以Matlab仿真为核心,建议读者结合相关控制理论知识,深入理解代码实现细节,重点关注动力学建模、控制律设计与推力分配模块。在学习过程中,应动手调试参数,复现文中翻转动作的仿真结果,并尝试拓展至其他复杂飞行任务,以加深对无人机控制机理的理解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值