当前位置:文档之家› 开发平台学习笔记

开发平台学习笔记

一.前台前台主要分成jsp和其相对应的js两个组成部分二.后台后台分成: view层,model层,dao层, custom层( 1 )View层:1 ·图1-1VIEW层示意图图1-12·关于“View.java”(1)命名:一般情况下,View层的命名方式会已相关逻辑的实现的拼音的简写加上View进行命名。

例如:我们要开发一个名称为”经费审批单”的税务行政单据。

那么这个时候View层就要命名为JfSpView.java(2)View类的继承:通常一个View层会继承一个父类,已用来实现其相关的注册权限和实现相关的功能。

一般情况下,View层次会继承的父类是OPMSCustomTreeViewServices 或OPMSCustomViewServices 两个父类。

其不同之处就在于继承前者便可以使用Tree组件。

继承父类后,View层必须实现两个方法这两个方法分别是:constructAfter(); 方法和setViewID(),其中后者的作用是根据View层注册的ID得到其相关的权限,这一点是至关重要的。

其通过setCustomViewID的方法放入相关的注册ID,这个ID要跟在系统”功能菜单注册”中所注册的功能菜单编号一致,已用来保证相关权限的正确性。

如下图:public void setViewId(){this.setCustomViewId("12533366334607460530");}框架中生成功能菜单注册的方法如下://生成菜单序号import com.taxinfo.frame.services.PublicServices;public class CDXH {public static void main(String args[]){for(int i=0;i<10;i++){System.out.println(PublicServices.getSequencesId());}}}注: 每个生成的功能菜单的注册ID只能使用一次。

( 3 ) 初始化方法initView。

一般在建立一个View同时我们给予它一个初始化的方法,其方法的名称为initView。

其作用是和前台的初始化界面的数据息息相关的。

在这里,这个方法不但完成了init初始化view层的功能,同时也可以通过JSON对前台界面初始化的时候绑定初始值。

如下图,initView方法会抛出一个SystemException异常,同时通过内部类来实现相关的初始化功能,其内部类通常会继承一个ListenerAction,其中会实现一个process的方法,方法同样会抛出SystemException和LoginException并通过listenerResult的setResultObject的方法返回结果。

通常情况下,在内部类的process方法中声明的ListenerResult对象会通过this.getDefaulListenerResult方法来获得一个ListenerResult对象。

public String initView() throws SystemException {InitViewImpl initView = new InitViewImpl();return initView.startListener();}protected class InitViewImpl extends ListenerAction { public ListenerResult process() throws SystemException,LogicException {ListenerResult l=this.getDefaultListenerResult();HyjfDto hyjfDto=new HyjfDto();l.setResultObject(hyjfDto);return l;}}Init方法的扩展应用: 一个View层可以有多个初始化的方法,此方法主要使用在主表和附表数据并存在界面上的情况。

这个时候,我们可以通过View层初始化主表信息的方法来绑定主表的数据,通过初始化附表的方法来绑定附表的数据。

从而达到双方互不干扰,功能实现明晰的目的,其具体情况如下://初始化附表的方法public String initView() throws SystemException {InitViewImpl initView = new InitViewImpl();return initView.startListener();}protected class InitViewImpl extends ListenerAction {public ListenerResult process() throws SystemException,LogicException {ListenerResult l=this.getDefaultListenerResult();HyjfDto hyjfDto=new HyjfDto();l.setResultObject(hyjfDto);return l;}}//初始化主表的方法public String initMain(String xh) throws SystemException{ InitMainImpl initMainImpl=new InitMainImpl();initMainImpl.setXh(xh);return initMainImpl.startListener();}protected class InitMainImpl extends ListenerAction{private String xh;public String getXh() {return xh;}public void setXh(String xh) {this.xh = xh;}public ListenerResult process() throwsSystemException,LogicException{ListenerResult l=this.getDefaultListenerResult();MainDto mainDto=new MainDto();l.setResultObject(mainDto);return l;}}( 4 ) View层中的实现功能的模式, 一种由功能实现方法调用内部实现类实现功能的模式:在框架的View中,通常,我们实现某项功能的时候都是通过,首先声明实现这种功能的函数(方法),然后通过这个函数(方法)来调用一个实现功能内部类。

再由这个内部类来调用Model和Dao层,从而返回结果给前台界面接受并展示。

(内部实现类的命名是:实现功能的方法+Impl)。

模式一:返回一个保存(增加,删除,保存)的结果public String saveHyjf(String mainDtoSrc,String hyjfDtoSrc)throws SystemException{SaveHyjfImpl saveHyjfImpl=new SaveHyjfImpl(); //调用SavaHyjfImpl内部实现类saveHyjfImpl.setMainDtoSrc(mainDtoSrc);saveHyjfImpl.setHyjfDtoSrc(hyjfDtoSrc);return saveHyjfImpl.startListener();}protected class SaveHyjfImpl extends ListenerAction{private String mainDtoSrc;private String hyjfDtoSrc;public String getMainDtoSrc() {return mainDtoSrc;}public void setMainDtoSrc(String mainDtoSrc) {this.mainDtoSrc = mainDtoSrc;}public String getHyjfDtoSrc() {return hyjfDtoSrc;}public void setHyjfDtoSrc(String hyjfDtoSrc) {this.hyjfDtoSrc = hyjfDtoSrc;}public ListenerResult process() throwsSystemException,LogicException{ListenerResult l;ListenerResult id; //接收查询的单据代码String djmc="济南市地税局会议经费审批表";XzdjglModule xzdjglModule=new XzdjglModuleImpl(getSession());MainDtomainDto=(MainDto)this.decode(this.getMainDtoSrc());HyjfDtohyjfDto=(HyjfDto)this.decode(this.getHyjfDtoSrc()); //页面传递的数据id=this.convert(xzdjglModule.getDjDm(djmc));//获得单据名称编号Map map=(Map)((List)id.getResultObject()).get(0);//把键和值放到MAP中String djdm=map.get("ID").toString(); //根据MAP中的键得到它的值mainDto.setDjmcDm(djdm);mainDto.setLrrdm(getSession().getUserShareInfo().getCzryD m()); //获得操作人员代码l=this.convert(xzdjglModule.saveHyjf(mainDto,hyjfDto));return l;}}模式二:返回一个String,Map,List(数据类型)的结果//返回一个String类型的结果,通过ListenerResult的setResultObject方法来返回public String getDjbh() throws SystemException{GetDjbhImpl getDjbhImpl=new GetDjbhImpl();return getDjbhImpl.startListener();}protected class GetDjbhImpl extends ListenerAction{public ListenerResult process() throws SystemException,LogicException{ListenerResult l=this.getDefaultListenerResult();//把默认值赋给lXzdjglModule xzdjglModule=new XzdjglModuleImpl(getSession());String bh=xzdjglModule.getHyjfBh();//用字符型接收Module返回的值l.setResultObject(bh);//把该值放到l中return l;}}//返回一个Map集合的方法public String getBrXxHyjf(String xh) throws SystemException{GetBrXxHyjf getBrXxHyjf=new GetBrXxHyjf();getBrXxHyjf.setXh(xh);return getBrXxHyjf.startListener();}protected class GetBrXxHyjf extends ListenerAction{private String xh; //唯一识别号public String getXh() {return xh;}public void setXh(String xh) {this.xh = xh;}public ListenerResult process() throws SystemException,LogicException{ListenerResult l=this.getDefaultListenerResult();TransactionResult t;XzdjglModule xzdjglModule=new XzdjglModuleImpl(getSession());t=xzdjglModule.getHyjfXx(this.getXh());Map map=(Map)((List)t.getResultObject()).get(0);//取得查询的结果并转成Map集合map.put("TXBMMC", this.dictServices("OPMS_SWJG", map.get("TXBM").toString()));map.put("SHRMC",getSession().getUserShareInfo().getCzryM c());map.put("SHRDM",getSession().getUserShareInfo().getCzryD m());l.setResultObject(map); //传递MAPreturn l;}}//模式三:返回一个查询的结果public String selectFwczxxMx(String zjlx, String zjhm, int pageIndex, String flag)throws SystemException {SelectFwczxxFzmxImpl selectFwczxxImpl = new SelectFwczxxFzmxImpl();selectFwczxxImpl.setZjlx(zjlx);selectFwczxxImpl.setZjhm(zjhm);selectFwczxxImpl.setPageIndex(pageIndex);selectFwczxxImpl.setFlag(flag);return selectFwczxxImpl.startListener();}protected class SelectFwczxxFzmxImpl extends ListenerAction { private String zjlx;private String zjhm;private int pageIndex;private String flag;public String getZjlx() {return zjlx;}public String getZjhm() {return zjhm;}public String getFlag() {return flag;}public void setZjlx(String zjlx) {this.zjlx = zjlx;}public void setZjhm(String zjhm) {this.zjhm = zjhm;}public void setFlag(String flag) {this.flag = flag;}public int getPageIndex() {return pageIndex;}public void setPageIndex(int pageIndex) {this.pageIndex = pageIndex;}public ListenerResult process() throws SystemException, LogicException {ListenerResult l = this.getDefaultListenerResult();SfglFwczxxcjFzmxModule sfglFwczxxcjFzmxModule = new SfglFwczxxcjFzmxModuleImpl(getSession());l = this.convert(sfglFwczxxcjFzmxModule.selectFwczFzxx(this.ge tZjlx(),this.getZjhm(), this.getPageIndex(), this.getFlag()));DataWindow dw = (DataWindow)l.getResultObject();//通过l的getResultObject 方法得到一个DataWindow对象List list = dw.getDataBuffer() ;//取出list准备准换码表this.dictConvertServices(list, "OPMS_CZRY", "ZGSWRY", "ZGSWRY_MC");this.dictConvertServices(list, "OPMS_SWJG", "SSKS", "SWJG_MC");this.dictConvertServices(list, "SFGL_DM_FWYTLX", "FWYT_LX", "FWYT_MC");this.dictConvertServices(list, "SFGL_DM_ZJLX", "ZJLX", "ZJLX_MC");l.setResultObject(dw); //将转化完的dw重新放入setResultObject中return l;}}综上所述:View 层作为框架后台中最先接触到得层次,相对于Model和Dao层,View层和界面的交互密度和交互关系更加的密集和牢靠,在前台界面中开发人员可以通过json 调用View中实现某项特定功能的方法,进而而由这个方法调用相关的内部实现类,内部实现类需要继承ListenerAction和抛出SystemException,LogicException 异常。

相关主题