J2EEXML建模
目录
用一个xml-config文件实例:
先看config.xml文件
再看 ActionModel
ConfigModel
ActionNotFoundException
ForwardNotFoundException
ConfigModelFactory
ActionDuplicateDefinitionException
ForwardDuplicateDefinitionException
InvalidPathException
用一个xml-config文件实例:
- ActionModel
- ConfigModel
- ForwardModel
- ActionNotFoundException
- ForwardNotFoundException
- ConfigModelFactory
- ActionDuplicateDefinitionException
- ForwardDuplicateDefinitionException
- InvalidPathException
先看config.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE config[<!ELEMENT config (action*)><!ELEMENT action (forward*)><!ELEMENT forward EMPTY><!ATTLIST actionpath CDATA #REQUIREDtype CDATA #REQUIRED><!ATTLIST forwardname CDATA #REQUIREDpath CDATA #REQUIREDredirect (true|false) "false">
]>
<config><action path="/studentAction" type="org.lisen.mvc.action.StudentAction"><forward name="students" path="/students/studentList.jsp" redirect="false"/></action>
</config>
再看 ActionModel
package com.zking.mymvc.framework;import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;/*** ActionModel类:表示一个Action的模型,包含了Action的路径、类型、转发模型、重定向等属性* */
public class ActionModel {private String path; //Action的路径private String type; //Action的类型,例如:request、ajax等private static Pattern pattern = Pattern.compile("^/.+$"); //静态的正则表达式,用于匹配Action的路径private Map<String, ForwardModel> forwardmap = new HashMap<>(); //转发模型的HashMapprivate Boolean redirect; //是否重定向public String getPath() {return path;}public void setPath(String path) {checkPath(path); //校验Action的路径是否符合规范,即必须以/开头this.path = path;}public String getType() {return type;}public void setType(String type) {this.type = type;}// put()方法用于将ForwardModel转发模型添加到HashMap集合中;public void put(ForwardModel forward) {if(!forwardmap.containsKey(forward.getName())) {forwardmap.put(forward.getName(), forward); //添加转发模型}else {throw new ForwardDuplicateDefinitionException("forward name:"+forward.getName()+" 不能重复");//如果转发模型已经存在,则抛出ForwardDuplicateDefinitionException异常}}// find()方法用于查找指定名称的转发模型,如果不存在则抛出ForwardNotFoundException异常public ForwardModel find(String name) {if(!forwardmap.containsKey(name)) {return forwardmap.get(name);}else {throw new ForwardNotFoundException("forward name:"+name+"不存在");//如果转发模型不存在,则抛出ForwardNotFoundException异常}}// setRedirect()方法用于设置属性redirect的值必须为true或者false;public void setRedirect(String redirect) {if("true".equals(redirect) || "false".equals(redirect)){this.redirect=Boolean.valueOf(redirect);}else {throw new RuntimeException("属性redirect的值必须为true或者false");//如果属性redirect的值不为true或者false,则抛出RuntimeException异常}}// checkPath()方法用于校验路径是否符合规范,即必须以/开头;public void checkPath(String path) {Matcher matcher = pattern.matcher(path); //匹配Action的路径是否符合规范boolean b = matcher.matches();if(!b) {throw new InvalidPathException("ForwardModel.path["+path+"]必须以/开头");//如果Action的路径不符合规范,则抛出InvalidPathException异常}}}
ConfigModel
public class ConfigModel {private Map<String, ActionModel> actionMap = new HashMap<>();//根据指定的路径 path,在 actionMap 中查找对应的 ActionModel 对象并返回。public ActionModel find(String path) {if(actionMap.containsKey(path)) {return actionMap.get(path);}else {throw new RuntimeException("action path:"+path+"没有找到");}}//将指定的 ActionModel 对象存储到 actionMap 中。public void put(ActionModel action) {if(!actionMap.containsKey(action.getPath())) {actionMap.put(action.getPath(), action);}else {//如果该对象的路径已经存在于 actionMap 中,则抛出自定义的 ActionDuplicateDefinitionException 异常,提示路径重复定义。 throw new ActionDuplicateDefinitionException("action path:"+action.getPath()+"重复定义");}}}
ForwardModel
public class ForwardModel {private String name;private String path;private boolean redirect;public String getName() {return name;}public void setName(String name) {this.name = name;}public String getPath() {return path;}public void setPath(String path) {this.path = path;}public boolean isRedirect() {return redirect;}public void setRedirect(String redirect) {this.redirect = Boolean.valueOf(redirect);}}
ActionNotFoundException
/** action找不到指定路径*/
public class ActionNotFoundException extends RuntimeException{public ActionNotFoundException() {super();}public ActionNotFoundException(String msg) {super(msg);}public ActionNotFoundException(String msg,Throwable cause) {super(msg,cause);}}
ForwardNotFoundException
public class ForwardModel {private String name;private String path;private boolean redirect;public String getName() {return name;}public void setName(String name) {this.name = name;}public String getPath() {return path;}public void setPath(String path) {this.path = path;}public boolean isRedirect() {return redirect;}public void setRedirect(String redirect) {this.redirect = Boolean.valueOf(redirect);}}
ConfigModelFactory
public class ConfigModelFactory {//私有化构造方法,确保该类不会被实例化private ConfigModelFactory() {}//使用饿汉模式,类加载时就初始化了config对象private static ConfigModel config = null;static {//读取配置文件config.xmlInputStream in = ConfigModelFactory.class.getResourceAsStream("/config.xml");SAXReader reader = new SAXReader();Document doc;try {doc = reader.read(in);Element root = doc.getRootElement();config = new ConfigModel();//读取每个action节点List<Element> actions = root.selectNodes("action");for (Element action : actions) {String actionPath = action.attributeValue("path");String actionType = action.attributeValue("type");//创建ActionModel对象ActionModel actionModel = new ActionModel();actionModel.setPath(actionPath);actionModel.setType(actionType);//读取每个action节点下的forward子节点List<Element> forwards = action.selectNodes("forward");for (Element forward : forwards) {String forwardPath = forward.attributeValue("path");String forwardName = forward.attributeValue("name");String redirect = forward.attributeValue("redirect");//创建ForwardModel对象ForwardModel forwardModel = new ForwardModel();forwardModel.setPath(forwardPath);forwardModel.setName(forwardName);forwardModel.setRedirect(redirect);//将ForwardModel对象放入ActionModel对象中actionModel.put(forwardModel);}//将ActionModel对象放入ConfigModel对象中config.put(actionModel);}} catch (Exception e) {//抛出运行时异常throw new RuntimeException("解析config.xml发生异常", e.getCause());}}//提供一个方法获取config对象public static ConfigModel getConfigModel() {return config;}public static void main(String[] args) throws DocumentException {//测试ActionModel action = config.find("/studentAction");System.out.println(action.getType());System.out.println("yes");}
}
ActionDuplicateDefinitionException
/** action重复定义异常*/
public class ActionDuplicateDefinitionException extends RuntimeException{public ActionDuplicateDefinitionException() {super();}public ActionDuplicateDefinitionException(String msg) {super(msg);}public ActionDuplicateDefinitionException(String msg,Throwable cause) {super(msg,cause);}
}
ForwardDuplicateDefinitionException
/*** forward重复定义异常* @author PC**/
public class ForwardDuplicateDefinitionException extends RuntimeException{public ForwardDuplicateDefinitionException() {super();}public ForwardDuplicateDefinitionException(String msg) {super(msg);}public ForwardDuplicateDefinitionException(String msg,Throwable cause) {super(msg,cause);}
InvalidPathException
public class InvalidPathException extends RuntimeException{public InvalidPathException() {super();}public InvalidPathException(String msg) {super(msg);}public InvalidPathException(String msg,Throwable cause) {super(msg,cause);}
相关文章:
J2EEXML建模
目录 用一个xml-config文件实例: 先看config.xml文件 再看 ActionModel ConfigModel ActionNotFoundException ForwardNotFoundException ConfigModelFactory ActionDuplicateDefinitionException ForwardDuplicateDefinitionException InvalidPathExcept…...
vue中export和export default
参考:vue中export和export default的使用 参考:vue里的export default...
转职做项目经理,我为什么选择PMP?
老实说,在学习PMP之前,我做了很长时间的思想斗争,一是平时工作有些忙,没有大块儿时间集中学习;二是不确定考完之后是否真能用上。但现在我可以很明确的告诉每一个想学习PMP的人:放心学吧,知识不…...
LangChain(5)Conversational Agents
Large Language Models (LLMs) 在语义知识方面表现不错,但也有一些不足,如:不能正确计算数学公式、无法获取最新知识新闻 通过 Agents 可以赋予 LLMs 更多能力,让LLM能够计算、上网查询 agent 简单使用 from langchain import …...
【云原生】Kubernetes临时容器
临时容器 特性状态: Kubernetes v1.25 [stable] 本页面概述了临时容器:一种特殊的容器,该容器在现有 Pod 中临时运行,以便完成用户发起的操作,例如故障排查。 你会使用临时容器来检查服务,而不是用它来构建…...

Jenkins+Robot 接口自动化测试
目录 前言: 设计目标 项目说明 目录结构 配置 jenkins 1.安装插件 2.配置项目 前言: JenkinsRobot是一种常见的接口自动化测试方案,可以实现自动化的接口测试和持续集成。Jenkins是一个流行的持续集成工具,而Robot Framew…...

【Visual Studio Code】---自定义键盘快捷键设置
概述 一个好的文章能够帮助开发者完成更便捷、更快速的开发。书山有路勤为径,学海无涯苦作舟。我是秋知叶i、期望每一个阅读了我的文章的开发者都能够有所成长。 一、进入键盘快捷键设置 1、进入键盘快捷键设置方法1 使用快捷键进入键盘快捷键设置先按 Ctrl K再…...

FastEdit ⚡:在10秒内编辑大型语言模型
概述: 这个仓库旨在通过一个单一的命令,有效地将新鲜且定制化的知识注入到大型语言模型中,以辅助开发人员的工作。 支持的模型:○ GPT-J (6B)○ LLaMA (7B/13B)○ BLOOM (7.1B)○ Falcon (7B)○ Baichuan (7B/13B)○ InternLM (7…...

SpringBoot + Docker 实现一次构建到处运行
一、容器化部署的好处 Docker 作为一种新兴的虚拟化方式,它可以更高效的利用系统资源,不需要进行硬件虚拟以及运行完整操作系统等额外开销。 传统的虚拟机技术启动应用服务往往需要数分钟,而 Docker 容器应用,由于直接运行宿主内…...
Spring-Cloud-Gateway如何自定义断言工厂?
遇到这么一个面试题:如何在网关做配置,实现只有在早晨9点到下午18点之间接口才允许访问,其他时间访问都是404。 我们知道网关的一个重要的作用就是路由转发,路由表的配置大概是这个样子: spring:cloud:gateway:routes:- id: user…...

Android平台如何高效率实现GB28181对接?
技术背景 GB28181协议是一种用于设备状态信息报送的协议,可以在不同设备之间进行通信和数据传输。 在安卓系统上实现GB/T 28181非常必要,GB28181协议实现分两部分,一部分是信令,另外一部分就是媒体数据的编码。 信令主要包括S…...

vue2 实现后台管理系统左侧菜单联动实现 tab根据路由切换联动内容,并支持移动端框架
效果图: pc端 移动端 由于代码比较多,我这里就不一一介绍了,可以去我的git上把项目拉下来 git地址https://gitee.com/Flechazo7/htglck.git 后台我是用node写的有需要的可以评论联系...

一本通1910:【00NOIP普及组】计算器的改良题解
今天是编程集训的第二天,也是我来到CSDN整整1年。感谢所有阅读过我的文章的人,谢谢。 今天的比赛难度略低于昨天,但这道题也卡了我好久。 进入正题 题目: 题目描述: NCL是一家专门从事计算器改良与升级的实验室&a…...

golang网络编程学习-1rpc
网络编程主要的内容是: 1.TCP网络编程 2.http服务 3.rpc服务 4.websocket服务 一、rpc RPC 框架----- 远程过程调用协议RPC(Remote Procedure Call Protocol)-----允许像调用本地服务一样调用远程服务。 RPC是指远程过程调用,也就是说两台服…...

【MQTT】Esp32数据上传采集:最新mqtt插件(支持掉线、真机调试错误等问题)
前言 这是我在Dcloud发布的插件-最完整Mqtt示例代码(解决掉线、真机调试错误等问题),经过整改优化和替换Mqtt的js文件使一些市场上出现的问题得以解决,至于跨端出问题,可能原因有很多,例如,合法…...

基于PyQt5的UI界面开发——对基本控件的介绍
基本控件介绍 在PyQt中,控件是用户界面上的可见元素。控件可以包括按钮、标签、文本框、进度条等。每个控件都有自己的属性和方法,可以通过编程方式进行调整和操作。 以下是一些常用的PyQt控件: QLabel(标签)&#…...
flink 报错:Caused by: java.lang.RuntimeException: Assigned key must not be null!
问题描述 不同情况下需要找对应的解决方法,这里介绍的解决方法不能拓展到别的场景。 场景描述: flink job 的开发过程中遇到这样的需求,需要先 map 处理,然后把返回的 DataStream 作为输入,流入别的 map 中。这里我们遇…...

AN OVERVIEW OF LANGUAGE MODELS RECENT DEVELOPMENTS AND OUTLOOK
LLM系列相关文章,针对《AN OVERVIEW OF LANGUAGE MODELS: RECENT DEVELOPMENTS AND OUTLOOK》的翻译。 语言模型综述:近年来的发展与展望 摘要1 引言2 语言模型的类型2.1 结构化LM2.2 双向LM2.3 置换LM 3 语言单元3.1 字符3.2 单词和子单词3.2.1 基于统…...

ArcGIS、ENVI、InVEST、FRAGSTATS等多技术融合提升
专题一 空间数据获取与制图 1.1 软件安装与应用讲解 1.2 空间数据介绍 1.3海量空间数据下载 1.4 ArcGIS软件快速入门 1.5 Geodatabase地理数据库 专题二 ArcGIS专题地图制作 2.1专题地图制作规范 2.2 空间数据的准备与处理 2.3 空间数据可视化:地图符号与注…...

fastapi初使用,构建自己的api
文章目录 1、安装2、api实现2.1、 app.get("/1")2.2、app.get("/{a}")2.3、app.get("/{a}{b}")2.4、函数和api分离 3、运行 原文链接:https://wangguo.site/posts/d98bb3c9.html fastapi 是一个基于 Python 的 API 构建框架ÿ…...

深入浅出Asp.Net Core MVC应用开发系列-AspNetCore中的日志记录
ASP.NET Core 是一个跨平台的开源框架,用于在 Windows、macOS 或 Linux 上生成基于云的新式 Web 应用。 ASP.NET Core 中的日志记录 .NET 通过 ILogger API 支持高性能结构化日志记录,以帮助监视应用程序行为和诊断问题。 可以通过配置不同的记录提供程…...
基于大模型的 UI 自动化系统
基于大模型的 UI 自动化系统 下面是一个完整的 Python 系统,利用大模型实现智能 UI 自动化,结合计算机视觉和自然语言处理技术,实现"看屏操作"的能力。 系统架构设计 #mermaid-svg-2gn2GRvh5WCP2ktF {font-family:"trebuchet ms",verdana,arial,sans-…...

STM32F4基本定时器使用和原理详解
STM32F4基本定时器使用和原理详解 前言如何确定定时器挂载在哪条时钟线上配置及使用方法参数配置PrescalerCounter ModeCounter Periodauto-reload preloadTrigger Event Selection 中断配置生成的代码及使用方法初始化代码基本定时器触发DCA或者ADC的代码讲解中断代码定时启动…...
【磁盘】每天掌握一个Linux命令 - iostat
目录 【磁盘】每天掌握一个Linux命令 - iostat工具概述安装方式核心功能基础用法进阶操作实战案例面试题场景生产场景 注意事项 【磁盘】每天掌握一个Linux命令 - iostat 工具概述 iostat(I/O Statistics)是Linux系统下用于监视系统输入输出设备和CPU使…...
【决胜公务员考试】求职OMG——见面课测验1
2025最新版!!!6.8截至答题,大家注意呀! 博主码字不易点个关注吧,祝期末顺利~~ 1.单选题(2分) 下列说法错误的是:( B ) A.选调生属于公务员系统 B.公务员属于事业编 C.选调生有基层锻炼的要求 D…...

《基于Apache Flink的流处理》笔记
思维导图 1-3 章 4-7章 8-11 章 参考资料 源码: https://github.com/streaming-with-flink 博客 https://flink.apache.org/bloghttps://www.ververica.com/blog 聚会及会议 https://flink-forward.orghttps://www.meetup.com/topics/apache-flink https://n…...

自然语言处理——循环神经网络
自然语言处理——循环神经网络 循环神经网络应用到基于机器学习的自然语言处理任务序列到类别同步的序列到序列模式异步的序列到序列模式 参数学习和长程依赖问题基于门控的循环神经网络门控循环单元(GRU)长短期记忆神经网络(LSTM)…...

Reasoning over Uncertain Text by Generative Large Language Models
https://ojs.aaai.org/index.php/AAAI/article/view/34674/36829https://ojs.aaai.org/index.php/AAAI/article/view/34674/36829 1. 概述 文本中的不确定性在许多语境中传达,从日常对话到特定领域的文档(例如医学文档)(Heritage 2013;Landmark、Gulbrandsen 和 Svenevei…...
LeetCode - 199. 二叉树的右视图
题目 199. 二叉树的右视图 - 力扣(LeetCode) 思路 右视图是指从树的右侧看,对于每一层,只能看到该层最右边的节点。实现思路是: 使用深度优先搜索(DFS)按照"根-右-左"的顺序遍历树记录每个节点的深度对于…...
【Nginx】使用 Nginx+Lua 实现基于 IP 的访问频率限制
使用 NginxLua 实现基于 IP 的访问频率限制 在高并发场景下,限制某个 IP 的访问频率是非常重要的,可以有效防止恶意攻击或错误配置导致的服务宕机。以下是一个详细的实现方案,使用 Nginx 和 Lua 脚本结合 Redis 来实现基于 IP 的访问频率限制…...