目录
一、学会XML建模
今天我们来看看如何XML建模,首先还是先把建模的XML文件【config.xml】放在这里:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<action path="/regAction" type="test.RegAction">
<forward name="failed" path="/reg.jsp" redirect="false" />
<forward name="success" path="/login.jsp" redirect="true" />
</action>
<action path="/loginAction" type="test.LoginAction">
<forward name="failed" path="/login.jsp" redirect="false" />
<forward name="success" path="/main.jsp" redirect="true" />
</action>
</config>
我们先来分析一下这个xml文件:
1) 分析标签
一个根标签:config
一个子标签:action
action内有子标签:forward
2) 分析属性
action:path、type
forward:name、path、redirect
根据上面分析我们可以知道此配置文件一共有三个不同的标签:
config:有子标签、没有属性
action:有子标签
forward:没有子标签
因此我们开始我们建模的第一步,
利用面向对象编程思想分别为不同的标签建设实体类:
ForwardModel:
package com.leaf.mode;
/**
* forward标签
* @author Leaf
*
* 2022年6月15日 上午8:40:48
*/
public class ForwardModel {
//<forward name="success" path="/main.jsp" redirect="true" />
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(boolean redirect) {
this.redirect = redirect;
}
public ForwardModel() {
}
public ForwardModel(String name, String path, boolean redirect) {
this.name = name;
this.path = path;
this.redirect = redirect;
}
@Override
public String toString() {
return "ForwardMode [name=" + name + ", path=" + path + ", redirect=" + redirect +