📄 abstractcmdaction.java
字号:
package com.easyjf.web.tools;
import java.lang.reflect.Method;
import com.easyjf.util.CommUtil;
import com.easyjf.web.IWebAction;
import com.easyjf.web.Module;
import com.easyjf.web.Page;
import com.easyjf.web.WebForm;
/**
*
* <p>Title: 通过命令式Action类</p>
* <p>Description: 这是一个对Action命令进行封装的抽象类,用于为提供命令式WebAction的写法用户直接调用,可以减少书写繁锁的if语句</p>
* easyJWebCommand命令del(或Del)对应Action类的doDel方法
* <p>Copyright: Copyright (c) 2006</p>
* <p>Company: www.easyjf.com</p>
* @author 蔡世友
* @version 1.0
*/
public abstract class AbstractCmdAction implements IWebAction {
public Page execute(WebForm form, Module module) throws Exception {
Object beforeCheck=doBefore(form,module); //模版方法
if(beforeCheck!=null)
{
//如果Action执行前检查,返回Page则直接跳转
if(beforeCheck.getClass()==Page.class)return (Page)beforeCheck;
}
Page forward=null;
String command=CommUtil.null2String(form.get("easyJWebCommand"));
if(!"".equals(command))
{
Class[] paras=new Class[2];
paras[0]=WebForm.class;
paras[1]=Module.class;
String cmd="do"+command.substring(0,1).toUpperCase()+command.substring(1);
Method m=this.getClass().getMethod(cmd,paras);
if(m!=null)
{
Object[] objs=new Object[2];
objs[0]=form;
objs[1]=module;
Object ret=m.invoke(this,objs);
if(ret instanceof Page)forward=(Page)ret;
}
else
throw new Exception("方法名称不正确,在"+this.getClass()+"中找不到"+cmd+"方法!请确认您页面中的easyJWebCommand参数值是否正确!");
}
else
forward=doInit(form,module);
doAfter(form,module);
return forward;
}
/**
* 在执行具体的doCommond方法前执行
* @param form
* @param module
* @return
*/
public Object doBefore(WebForm form,Module module){return null;};//Action前置校验
/**
* 在没有输入任何命令的时候执行
* @param form
* @param module
* @return
*/
public abstract Page doInit(WebForm form,Module module);//初始化数据,如表单项及默认值等
/**
* 在执行doCommand方法后执行
* @param form
* @param module
* @return
*/
public Object doAfter(WebForm form,Module module){return null;};//Action后置处理
/**
* @param args
*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -