电力系统技术总结笔记0天_第1页
电力系统技术总结笔记0天_第2页
电力系统技术总结笔记0天_第3页
电力系统技术总结笔记0天_第4页
电力系统技术总结笔记0天_第5页
免费预览已结束,剩余144页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

电力系统总结笔一:项目第一天(项目框架jar包(1)在 .elec.中创建publicpublicclassElecTextimplementsjava.io.Serializable<?xml<?xmlversion="1.0"encoding="UTF-<!DOCTYPEhibernate- "-//Hibernate/HibernateMap DTD3.0//EN" <class .ElecText"<idname="textID"type="string"<generator<propertyname="textName"type="string"<propertyname="textDate"type="date"<propertyname="textRemark"type="string"privateStringtextID; privateStringtextName; privateDatetextDate; privateStringtextRemark;//测试备publicStringgetTextID()return}publicvoidsetTextID(StringtextID)this.textID=}publicStringgetTextName()return}publicvoidsetTextName(StringtextName)this.textName=}publicDategetTextDate()return}publicvoidsetTextDate(DatetextDate)this.textDate=}publicStringgetTextRemark()return}publicvoidsetTextRemark(StringtextRemark)this.textRemark=}}><?xml<?xmlversion="1.0"encoding="UTF-<!DOCTYPEhibernate-configuration"-//Hibernate/HibernateConfigurationDTD3.0//EN"连接数据库的信息 <property<property<property<property<!--加 文件-- (4)junittestpublicclassTestHibernatepublicvoidConfigurationconfiguration=newConfiguration(); SessionFactorysf=configuration.buildSessionFactory();Sessions=sf.openSession();Transactiontr= ecText=newElecText();elecText.setTextDate(newDate());}}第四步:DAO在cn..elec.dao中创建2个接口(公用接口和业务接口publicpublicinterfaceICommonDao<T>voidsave(T}业务接口(需要继承公共接口,并且指定泛型TpublicpublicinterfaceIElecTextDaoextendsICommonDao<ElecText>publicstaticfinalStringSERVICE_NAME= }在 .elec.dao.impl中创建2个接口的实现}}publicvoidsave(Tentity)}publicfinalvoidsetSessionFactoryDi(SessionFactorysessionFactory){}ICommonDao<T>publicclassCommonDaoImpl<T>extendsHibernateDaoSupportpublicclassElecTextDaoImplextendsCommonDaoImpl<ElecText>IElecTextDao}}srcspring的配置文件<?xmlversion="1.0"encoding="UTF-<beans <!--1:开启对注解的支持,组件的自动扫描,扫描在类上定义的@Controller@Service .elec的包--> ponent-scanbase- 2先不写,大家想想项目中应该添加什么? <beanid="sessionFactory"加载类路径下的hibernate.cfg.xml<property 事务管理器(切面<beanid="trManager"<propertyname="sessionFactory"5:注解,在Service的类或者是Service的方法上,添加@Transcational()注解,用来控制事务--><tx:annotation-driventransaction-<!--<tx:advice<tx:adviceid="aa"transaction-<tx:methodname="update*"isolation="DEFAULT"propagation="REQUIRED"read-only="false"/><tx:methodname="delete*"isolation="DEFAULT"propagation="REQUIRED"read-only="false"/><tx:methodname="*"read-<aop:pointcutexpression="execution(* .elec.service..*.*(..))"id="bb"/><aop:advisoradvice-ref="aa"pointcut-junitpublicpublicclassTestDaopublicvoidApplicationContextac=newIElecTextDaoelecTextDao=(IElecTextDao) ecText=newElecText();elecText.setTextDate(newDate());}}使用hibernate的方式提交事务(自动提交)<property 第五步:Service在cn..elec.service中创建接口publicpublicinterfaceIElecTextServicepublicstaticfinalStringSERVICE_NAME void }(2)publicclassElecTextServiceImplimplementsIElecTextServiceprivateIElecTextDaoelecTextDao;publicvoidsaveElecTex ecText){}}(3)使用junit由于由于spring提供的式事务处理,进行事务的控制,在业务层的类和方法上定义publicclassTestServicepublicvoidsave(){ApplicationContextac=newIElecTextServiceelecTextService=(IElecTextService) ecText=newElecText();elecText.setTextDate(newDate()); }}@Transactional(),同时去掉hibernate.cfg.xml中的配置,由spring控制。去掉的代<property 第六步:控制层(@Scoevalue=prototyeAction是多实例,多线程publicclassElecTextActionextendsecText=privateIElecTextServicepublicStringreturn"save";}}publicpublicClassentityClass=tryentity=(T)}catch(Exceptione){}TprotectedHttpServletRequestprotectedHttpServletResponseModelDriven<T>,ServletRequestAware,ServletResponseAwarepublicclassBaseAction<T>extendsActionSupport}}publicTgetModel()return}publicvoidsetServletRequest(HttpServletRequestreq)this.request=}publicvoidsetServletResponse(HttpServletResponseres)this.response=}}在cn..elec.util包下创建公用类(泛型转换publicclassTUtilspublicclassTUtilspublicstaticClassgetTClass(Classentity){ParameterizedTypeparameterizedType=(ParameterizedType)ClassentityClass=(Class)return}}srcstruts2<?xml<?xmlversion="1.0"encoding="UTF-<!DOCTYPEstruts"-//ApacheSoftwareFoundation//DTDStrutsConfiguration2.3//EN" <constantname="struts.devMode"<!--设置 <constantname="struts.ui.theme" <constantname="struts.action.extension"系统管理<package<packagename="system"namespace="/system"extends="struts-<actionname="elecTextAction_*"class="elecTextAction"<result<web-appversion="2.5"" <web-appversion="2.5"" 器)--<<e-<点击【保存】完成。测试保存ElecTextSSHpublicclassCommonDaoImpl<T>extendsHibernateDaoSupport ICommonDao<T>ICommonDao<T>ClassentityClass=publicfinalvoidsetSessionFactoryDi(SessionFactorysessionFactory)}publicvoidsave(Tentity)}publicvoidupdate(Tentity)}publicTfindObjectByID(Serializableid)return(T)this.getHibernateTemplate().get(entityClass,}publicvoiddeleteObjectByIDs(Serializable...ids)if(ids!=null&&for(SerializableObjectentity=this.findObjectByID(id);}}}publicvoiddeleteObjectByCollection(List<T>list)} *SELECToFROMElecTextoWHERE1=1 ANDo.textNameLIKE'%张%' ANDo.textRemarkLIKE'%张%' ORDERBYo.textDateASC,o.textName publicList<T>findCollectionByConditionNoPage(StringfinalObject[]params,Map<String,String>orderby)Stringhql="SELECToFROM"+entityClass.getSimpleName()+"oWHERE1=1";StringorderByHql=this.initOrderByHql(orderby);finalStringfinalHql=hql+condition+ List<T>list=this.getHibernateTemplate().find(finalHql, SessionFactorysf= Sessions= Queryquery= query.setParameter(0, query.setParameter(1, List<T>list=List<T>list=this.getHibernateTemplate().execute(newHibernateCallback(){publicObject nHibernate(Sessionsession)throwsHibernateException,SQLException{Queryquery=session.createQuery(finalHql);if(params!=null&¶ms.length>0){for(inti=0;i<params.length;i++){query.setParameter(i,params[i]);}}return}return}privateStringinitOrderByHql(Map<String,String>orderby){StringBufferbuffer=newStringBuffer("");if(orderby!=null&&orderby.size()>0){buffer.append("ORDERBYforfor(Map.Entry<String,String>map:orderby.entrySet()){buffer.append(map.getKey()+""+map.getValue()+",");}}return}}4Mavenpom.xml通过坐标(jar包导入到项目中,如果版本升级,只需要改ssh(SSH)ssh需要的pom.xml第一步:在eclipsemaven工程maven工程src/main/javajava文件src/main/resources:存放配置文件src/test/javajava文件5Svn优点:使得项目组开发代码使用svn服务器进行版本控制常用令:Share查看svn的。6:java7(stuts2+sprin+hiberate二:项目第二天(运行(2)(3)标题是/title.jsp左侧菜单是frame框架改变是<FRAMESETborder=0frameSpacing=0rows=82,*<FRAMESETborder=0frameSpacing=0rows=82,*frameBorder=0<FRAMEname=topFramenoResizeontextPath<FRAMESETid="main"border="0"frameSpacing="0"frameBorder="0"<FRAME<framename="changeButton"ontextPath/left.jsp"ontextPath/change.jsp"marginHeight=0marginWidth=0scrolling=no<FRAMEontextPath/loading.jsp"(4)(5)ontextPath.css"ontextPath<linkrel="stylesheet"ontextPath.css"ontextPath<linkrel="stylesheet"<script ontextPath <script ontextPath<linktype="text/css"ontextPath}/script/jquery-ztree-<scriptontextPath}/script/jquery-<script<TABLE<TABLEborder=0<TDwidth=340pxalign=center<div<ul Tree"class="tree"id第二步:tree.js ={setting:{isSimpleData:true,treeNodeKey:"mid",treeNodeParentKey:"pid",showLine:true,root:isRoot:true,nodes:[] ={setting:{isSimpleData:true,treeNodeKey:"mid",treeNodeParentKey:"pid",showLine:true,root:isRoot:true,nodes:[]}}.setting, varprivilegeDate=mid:pid:isParent: name:'技术设施 varprivilegeDate=mid:pid:isParent: name:'技术设施 { }]},mid:pid:name技术资料图纸管理 isParent:true,{ }](6)functionfunction{ { ontextPath}}else{ ontextPath}}change.jsphome.jsphome.jsp通过框架加载change.jspchange.jspparenthome.jsp中的(7)function{ function{ { }else { }} { }else { }}}}functionwindow}}functionwindow}使用DIV控制数据的隐藏和显actingIndex.jsp中添加功能:js<link<linkhref="${pageContext<scriptlanguage="javascript"src="${pageContext ontextPath<tablecellspacing="0"cellpadding="1"rules="all"bordercolor="gray"border="1"id="DataGrid1"style="BORDER-RIGHT:gray1pxsolid;BORDER-TOP:gray1pxsolid;BORDER-LEFT:gray1pxsolid;WIDTH:100%;WORD-BREAK:break-all;BORDER-BOTTOM:gray1pxsolid;BORDER-COLLAPSE:collapse;BACKGROUND-COLOR:#f5fafe;WORD-WRAP:break-><tdalign="center"width="40%"height=22 ontextPath/images/tablehead.jpg">站点运行<tdalign="center"width="40%"height=22 ontextPath/images/tablehead.jpg">设备运行<tdalign="center"width="20%"height=22 ontextPath/images/tablehead.jpg">创建日期<divid="showInfomation"style="visibility:<tronmouseover="this.style.backgroundColor='white'"onmouseout="this.style.backgroundColor='#F5FAFE';"><tdstyle="HEIGHT:22px"align="center"<divclass="scrollStyle"align="left"onmouseover="showInfoWithPanel(this)"onmouseout="hiddenInfoPanel(this)"<s:property<s:property<tdstyle="HEIGHT:22px"align="center"<divclass="scrollStyle"align="left"onmouseover="showInfoWithPanel(this)"onmouseout="hiddenInfoPanel(this)"<s:property<tdstyle="HEIGHT:22px"align="center"<s:datename="createDate"format="yyyy-MM-dd控制文本域的输入字数第一步:在actingIndex.jsp<script<scriptlanguage="javascript"src="${pageContextontextPath <tdclass="ta_01"align="centerbgcolor="#f5fafe"width="15%"><tdclass="ta_01"bgcolor="#ffffff"style="word-break:break-<s:textareaname="stationRun"id="stationRun"cssStyle="width:500px;height:160px;padding:1;FONT-FAMILY:宋体;FONT-SIZE:9pt"<tdclass="ta_01"align="centerbgcolor="#f5fafe"width="15%"><tdclass="ta_01"bgcolor="#ffffff"style="word-break:break-padding:1;FONT-FAMILY:宋体;FONT-SIZE:9pt"jsfunctionfunctionvarstationRun=newBs_LimitedTextarea('stationRun',2500);stationRlineCssStyle="font-family:arial;font-size:11px;color:gray;";vardevRun=newBs_LimitedTextarea('devRun',2500);devRlineCssStyle="font-family:arial;font-size:11px;color:gray;";}}弹出窗口(windo.open()<input<inputstyle="font-size:12px;color:black;height=20;width=80" ontextPath;scriptfunction.js//open//opensizedfunctionopenWindow(sHref,strWidth,strHeight){varstrLeft=(screen.availWidth-strWidth)/2;varstrTop=(screen.availHeight-strHeight)/2;varstrRef="";varopenerobj=window.open(sHref,'newwin',strRef,false);}关闭窗口functionfunction}opener可以调用父页面的窗口对象,其中actingIndex.jsp(父页面)exportExcel.jsp(子页面exportExcel.jsp(子页面)openeractingIndex.jsp中的对象3:FCK旧版本:FCKfckTestmyeclipse下,发布项目,并运行fckTest的项目。fckEditmyeclipsefckEdit的项目。jseclipsemyeclipsejs,此时会非常浪费时间。由于这里使用的CkEditor+CKFinder也使用很多的js,所如果以后大家开发extjsjqueryeasyUI的项目,要求按照该方法去配置。整合项目的操作步骤:参照【技术资料\FCK文本编辑器\版本\ckeditor配置资料】中的config.skin'office2003编辑器皮肤样//config.skin'office2003编辑器皮肤样////config.toolbar=////config.toolbar=//使用自定义config.toolbar['Source','Preview','-['Undo','Redo','-','Find','Replace','-','SelectAll',['Image','Flash','Table','HorizontalRule','S ['Bold','Italic','Underline','-','Subscript',['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],['Link','Unlink','Anchor'],['Format','Font', ize','ShowBlocks','-',定义编辑器显示的效果4:js1:文件上传、(IO流2:数据的导入、导出(IO流4:数5:js123:系统(产生报告…,js三:项目第三天(数据字典2:hqlsqlStringStringhql="SELECTDISTINCTo.keywordFROMElecSystemDDLList<Object>list=StringStringhql="SELECTDISTINCTo.keyword,o.ddlNameFROMElecSystemDDLList<Object[]>list=StringStringhql="SELECTo,o.ddlNameFROMElecSystemDDLList<Object[]>list= Stringhql="SELECToFROMElecSystemDDL ecSystemDDL>list=(5)如果是hqlhqlFROMFROMElecSystemDDLecSystemDDL>list=3:页面使用select进行遍历 <option<s:iteratorvalue="#request.list"<optionvalue="<s:property<s:property<s:select<s:selectlist="#request.list"name="keyword"id="keyword"listKey="keyword"listValue="keyword"headerKey="jerrynew"headerValue=""cssClass="bg"cssStyle="width:180px"Jsfunctionfunctionvartb1=vartempRow$("#dictTbltr").size();//获取表格的行数var$tdNum=$("<tdalign='center'></td>");$tdNumvar$tdName=$("<td$tdName.html("<inputname=\"itemname\"type=\"text\"id=\""+tempRow+"\"size=\"45\"varvar$tdDel=$("<td$tdDelhtml("<ahref='javascript:delTableRow(\""+tempRow+"\")'><imgsrc=${pageContextreq ontextPath}/images/delete.gifwidth=15height=14border=0//创建tr,将3个td放置到trvar$tr=}functionvartb1=$("#dictTbl");vartempRow$("#dictTbltr").size();//获取表格的行数if(tempRow>rowNum){//获取删除行的id指定的对象,例如:<inputname=\"itemnametype=\"textid=\""+tempRow+"\"size=\"45\"maxlength=25>for(i=(parseInt(rowNum)+1);i<tempRow;i++){ $("#"+i).parent()next().html("<ahref='javascript:delTableRow(\""+(i-1)+"\")'><imgsrc=${pageContextreq ontextPath}/images/delete.gifwidth=15height=14border=0}}}Jspborder="1"style="BORDER-RIGHT:gray1pxsolid;BORDER-TOP:gray1pxsolid;BORDER-LEFT:gray1pxsolid;WIDTH:100%;WORD-BREAK:break-all;BORDER-BOTTOM:gray1pxsolid;BORDER-BACKGROUND-COLOR:#f5fafe;WORD-WRAP:break-<table cellpadding="1"rules="all"><tdclass="ta_01"align="center"width="20%"height=22 ontextPath}/images/tablehead.jpg"><tdclass="ta_01"align="center"width="60%"height=22 ontextPath/images/tablehead.jpg">名称<tdclass="ta_01"align="center"width="20%"height=22 ontextPath/images/tablehead.jpg">删除<tdclass="ta_01"align="center"<tdclass="ta_01"align="center"<inputname="itemname"type="text"size="45"<tdclass="ta_01"align="center"在使用 实现表格添加行和删除行的时候 获取页面填写的值,此时是一Ajax操作 对象:xmlreq=new ontextPath jsontextPathpub.jsvarvarreq=varhandlerFunction=Pub.getReadyStateHandler(req,req.onreadystatechange= req.open("POST",action, varstr=Pub.getParams2Str(sForm);}*创建ajax引*创建ajax引Pub.newXMLHttpRequest=functionnewXMLHttpRequest()varxmlreq=if(window.XMLHttpRequest){xmlreq=newXMLHttpRequest();}elseif(window.ActiveXObject)tryxmlreq=new}catch(e1)tryxmlreqxmlreq=new}catch(e2)}}}return}*@paramsForm:传递表单Form1*@paramsForm:传递表单Form1Pub.getParams2Str=functionvartryvar ifreturnvarfor(varfld=0;fld<objForm.elements.length;fld++){elt=objForm.elements[fld];strDiv=strDiv+strDiv=strDiv+}}catch(ex)return}return}*@paramreq:@parameleid:表单Form2@returnsPub.getReadyStateHandler=functiongetReadyStateHandler(req,eleid,responseXmlHandler){returnfunction() if(req.readyState==4) 果if(req.status==200) }elsealert("HTTPerror:return}}}方法五:将返回的结果dictionaryEdit.jsp,并放置到dictionaryIndex.jsp的Form2@paramdata@paramdata:服务器返回的结@parameleid:表单Form2Pub.handleResponse=functionvarele ele.innerHTML=data;}6:DOMfunctionfunction{var{if(str.charAt(i)!=""&&str.charAt(i)!="}}return}function{var{if(str.charAt(i)!="}return}function{return} return}了解:springc3p0,大家只要会配置即可,进度条(百分比)四:项目第四天(用户管理3:jqueryajaxstrutsjson<packagename="system"namespace="/system"extends="json-<!--默认将栈顶的对象,转换成<!--默认将栈顶的对象,转换成json对象,如果栈顶是一个集合,转换成json数组<resultname="findJctUnit"functionfindJctUnit(o){varfunctionfindJctUnit(o){varjct=$("#jctUnitIDoption")remove();if(data!=null&&for(varvarddlCode=data[i].ddlCode;varddlName=data[i].ddlName;var$option=}}}ActionList集合放置到栈顶,struts2publicpublicStringStringjctID=elecUser.getJctID(); ecSystemDDL>listreturn}ListListjson化。Listjsonjson化<!--默认将栈顶的对象,转换成json对象,如果栈顶是一个集<!--默认将栈顶的对象,转换成json对象,如果栈顶是一个集合,转换成json数组<resultname="findJctUnit"<param4:jqueryajax<packagename="system"namespace="/system"extends="json-<result<resultname="checkUser"的数据结果<param对象中的某个属性被json<param<paramfunctioncheckUser(o){varlogonName=$(o).val();$("#check").html("<fontcolor='red'>登录名不能为空</font>");ofocus();}else$(o)[0]}}}第四步:在ActionStringmessagepublicpublicStringStringlogonName=elecUser.getLogonName(); Stringmessage=returnreturn}第五步:在ServicemessagepublicpublicStringcheckUserByLogonName(StringlogonName){Stringmessage="";Stringcondition="ando.logonName=?";Object[]params={logonName}; if(list!=null&&list.size()>0){findCollectionByCmessage="2";}message=}}message=}return} { returnfalse;}}Jsfunctionfunction{varpatternif(pattern.test(strNumber))returnreturnreturn} 文件下传publicpublicclassFileUploadUtils*完成文件上 开publicstaticStringfileUploadReturnPath(Fileupload,StringuploadFileName,Stringmodel){Stringbasepath=Stringdatepath=DateUtils.dateToString(newStringperfixStringStringfilename=StringmodelPath=basepath+datepath+model;FiledateFile=new}FiledestFile=newreturn"/upload"+}publicstaticvoidmain(String[]args)throwsException FilesrcFile=newFiledestFile=new//FileUtils.copyFile(srcFile,booleanflag=srcFile.renameTo(destFile);}}<form<form<sfilename="upload"id="upload"cssStyle="width:450px;"></s:file>privateprivateFile[]privateString[]privateString[]<sfilename="upload"id="upload"<sfilename="upload"id="upload"cssStyle="width:450px;"></s:file>struts2提供的文件ActionpublicpublicStringdownload()throwsStringid=elecUser.getFileID();ElecUserFileelecUserFile=Stringpath= StringStringname=//处理中文问题,或者使用:nameURLEncoder.encode(name,UTF-8");name=newString(name.getBytes("gbk"),"iso-8859-1"); InputStreamin=newFileInputStream(newOutputStreamout=for(intb=-1;(b=in.read())!=-1;){}return}struts2提供的文件InputStream类型的属性,用来存放文件的输入流struts.xmlinputName的值一致。publicStringdownload()throwspublicStringdownload()throwsException{Stringid=elecUser.getFileID();ElecUserFileelecUserFile=StringStringpath= Stringname=//处理中文问题,或者使用:nameURLEncoder.encode(name,UTF-8");name=newString(name.getBytes("gbk"),"iso-8859-1");request.setAttribute("filename",name);InputStreamin=newFileInputStream(newreturn"fileSuccess";}8:使用md5的加理用户第一步:导入工具类,放置到cn..elec.util包privateprivatevoidmd5Password(ElecUserelecUser)StringlogonPwd=Stringmd5LogonPwd=logonPwd="123";}Stringpassword= 与输入 ifif(StringUtils.isNotBlank(password)&&password.equals(logonPwd)){md5LogonPwd=logonPwd;} 加MD5keyBeanmd5keyBean=newMD5keyBean();md5LogonPwd=md5keyBean.getkeyBeanofStr(logonPwd);}} <s:hiddenname="password"jquery的ajax完成业务操作,文件的上传和了解知识:md5的加密五:项目第五天(角色管理角色和权限的关系:不使用JsfunctioncheckAllOper(oper){}functiongoSelect(id){vararray===//}//}}}var$check=varflag=flag=true;returnfalse;}}}}}JspbgColor=bgColor="#f5fafe"border="0"<tdclass="ta_01"colspan=2align="left"width="100%"全选/全不选<inputtype="checkbox"<tablecellspacing="0"align="center"width="100%"cellpadding="1"rules="all"bordercolor="gray"border="1"style="BORDER-RIGHT:gray1pxsolid;BORDER-TOP:gray1pxsolid;BORDER-LEFT:gray1pxsolid;WORD-BREAK:break-all;BORDER-BOTTOM:gray1pxsolid;BORDER-COLLAPSE:collapse;BACKGROUND-COLOR:#f5fafe;WORD-WRAP:break-<s:iftest="#request.popedomList!=null&&<s:setvalue="%{'1'}"scope="request"<s:iteratorvalue="#request.popedomList"<s:if<s:if<s:setvalue="%{'1'}"scope="request"<tronmouseover="this.style.backgroundColor='white'"onmouseout="this.style.backgroundColor='#F5FAFE';"><tdclass="ta_01"align="left"width="18%"height="22"background="../images/tablehead.jpg"><s:if<inputtype="checkbox"name="selectoper"id="<s:propertyvalue="#popedom.mid"/>_<s:propertyvalue="#popedom.mid"/>"value="<s:propertyvalue="#popedom.pid"/>_<s:propertyvalue="#popedom.mid"/>"onClick='goSelect(this.id)'checked="checked"><inputtype="checkbox"name="selectoper"id="<s:propertyvalue="#popedom.mid"/>_<s:propertyvalue="#popedom.mid"/>"value="<s:propertyvalue="#popedom.pid"/>_<s:propertyvalue="#popedom.mid"/>"onClick='goSelect(this.id)'><s:property<s:if<tdclass="ta_01"align="left"width="82%"height="22">s:setvalue="%{'2'}"scope="request"var="flag"></s:set><s:if<inputtype="checkbox"name="selectoper"value=value="#popedom.pid"/>_<s:propertyvalue="#popedom.mid"/>"value="<s:propertyvalue="#popedom.pid"/>_<s:propertyvalue="#popedom.mid"/>"onClick='goSelect(this.id)'checked="checked"><inputtype="checkbox"name="selectoper"id="<s:propertyvalue="#popedom.pid"/>_<s:propertyvalue="#popedom.mid"/>"value="<s:propertyvalue="#popedom.pid"/>_<s:propertyvalue="#popedom.mid"/>"onClick='goSelect(this.id)'><s:property<inputtype="hidden"name="roleID"在使用<inputtype=”checkbox”>进行保存的时候,获取页面选中复选框value的属性值,此时是一个String类型的数组对象,可以采用遍历数组的方式,保存数据。<setname="elecRoles"<setname="elecRoles"table="elec_user_role"inverse="true"<column<column<many-to-many.ElecRole"elec_user_role的数据可以删除,但是角色表中数据也会被删除,这样显说明,由角色一端负责关联关系:也就是说角色可以操作用户,用户不能操作角色。重点:角色管理的开发,多和多的关联关系(hibernate,不使用六:项目第六天(系统登录1:struts2的validator校验(校验Js校验(前台校验Ajax校验 校验Struts2的validator校验 校验 校第一步:在Actionthis.addFieldError("error用户名输入有误!");return"error";}<action<actionAction_*"Action"<resultname="error">/WEB- /index.jsp中,定义:使用struts2的,输出错误信息:src2template/simplefielderror.ftl的文件放置到该文件夹下,此时启动的时候,就会覆盖struts包的下加载的内容<#list<#listeKeysas<#assigneValue=<#listeValueas<font<#if2:hibernatepublicpublicElecUserfindUserByLogonName(Stringname){Stringcondition="ando.logonName=?";Object[]params={name}; ecUser>list=elecUserDao.findCollectionByConditionNoPage(condition,params,null);ElecUserelecUser=null;if(list!=null&&list.size()>0){elecUser=}* returnelecUser;}方案二:在Service层的方法中(Session关闭之前publicpublicElecUserfindUserByLogonName(Stringname){Stringcondition="ando.logonName=?";Object[]params={name}; ecUser>list=elecUserDao.findCollectionByConditionNoPage(condition,params,null);ElecUserelecUser=null;if(list!=null&&list.size()>0){elecUser=}* returnelecUser;}}<setname="elecRoles"table="elec_user_role"<setname="elecRoles"table="elec_user_role"inverse="true"<column<many-to-many.ElecRole"建议项目开发中不要在.hbm.xmllazy=false,这样如果表关联比较多,不需要springOpenSessionInViewFilterweb容器中添加该过滤器web.xml中添加:的懒加载问题 1:事务提1:事务提交:spring提供 式事务控制,仍然在业务层的方法进行处理,方执行完毕后,事务会自动提交,如果出现异常,事务就会回滚。但是它延迟了执行完毕后,事务会自动提交,如果出现异常,事务就会回滚。但是它延迟了Session。OpenSessionInViewFilter,这样Session不关闭,另一个Session就无法,连接不第一步:index.jsp<tdwidth="100"><img ontextPath}/images/check.jpg"width="75"<inputtype="text"name="checkNumber"id="checkNumber"value=""maxlength="4"size="7"><imgsrc="${pageContext.req name="imageNumber"id="imageNumber"style="cursor:hand"title="点击可更换 height="20"onclick="checkNumberImage()"/>JsfunctionfunctionvarimageNumber imageNumber.srcimageNumber.src=}RandomRandomrandom=newRandom();StringsRand="";for(inti=0;i<4;i++)Stringrand=String.valueOf(random.nextInt(10));sRand+=rand;}将认证码存入tryImageIO.write(image,"JPEG",}catch(Exceptione)}第二步:在Action中进行校验,创建LoginUtilspublicpublicclassLogonUtilspublicstaticbooleancheckNumber(HttpServletRequestrequest)StringcheckNumber=returnfalse;} 的StringCHECK_NUMBER_KEY=returnfalse;}return}}第一步:index.sp<tdwidth="100"><imgontextPath}/images/remeber.jpg"<inputtype="checkbox"name="remeberMe"id="remeberMe"publicpublicclassLogonUtilspublicstaticvoidremeberMe(Stringname,Stringpassword,HttpServletRequestrequest,HttpServletResponseresponse){ = = StringremeberMe=if(remeberMe!=null&&remeberMe.equals("yes")){ } }}}Stringname="";Stringpassword="";Stringchecked=""; s= s!=null:name= checked="checked";} password= }}}index.jsp中的数据,jspjavajavajspjspjava代码,然后再执行。效率会降java代码抽取出去呢?publicpublicclassSystemFilterimplementsFilterpublicvoidinit(FilterConfigconfig)throwsServletException} publicvoiddoFilter(ServletRequestreq,ServletResponseres,FilterChainchain)throwsIOException,ServletException{HttpServletRequestrequest=(HttpServletRequest)HttpServletResponseresponse=(HttpServletResponse) Stringpath= chain.doFilter(request,}publicvoiddestroy()} privatevoidforwordIndexPage(Stringpath,HttpServletRequestrequest){if(path!=null&&path.equals("/index.jsp")){Stringname="";Stringpassword="";Stringchecked=""; s=request.get s!=null&& name= try{name=URLDecoder.decode(name,"UTF-}catch(UnsupportedEncodingExceptione){}checked=} password= }}}request.setAttribute("name",name);request.setAttribute("password",password);request.setAttribute("checked",checked);}}}}自定义过滤器,要求添加到struts2自定义过滤器,要求添加到struts2 测试后:发现问题:如果name中存在中文,此时中文字符是不能存放到对象中,使用HttpResponse对象添加会抛出异常。在过滤器SystemFiltername:tryname=在过滤器SystemFiltername:tryname=URLEncoder.encode(name,"UTF-}catch(UnsupportedEncodingExceptione){} = = name= tryname=URLDecoder.decode(name,"UTF-}catch(UnsupportedEncodingExceptione){}checked=}5:jqueryztree插件的使用(完成动态加载树型结构left.jsp<<scriptontextPath}/script/jquery-<scriptontextPath}/script/jquery-ztree-<script ontextPath <linktype="text/css"ontextPath.css"Left.jsp中使用<TABLE<TABLEborder=0<TDwidth=340pxalign=center<div<ul Tree"class="tree".js ={setting:{isSimpleData:true,treeNodeKey:"mid",treeNodeParentKey:"pid",showLine:true,root:isRoot:true,nodes:[]} .setting,}publicStringpublicStringStringpopedom=(String) ecPopedom>list=return }publicecPopedom>findPopedomListByUser(Stringpopedom)publicecPopedom>findPopedomListByUser(Stringpopedom)Stringcondition="ando.midIN('"+popedom.replace("@","','")+"')AND =?";Object[]params=Map<String,String>orderby=newLinkedHashMap<String,String>();orderby.put("o.mid","asc"); ecPopedom>list=elecPopedomDao.findCollectionByConditionNoPage(condition,params,orderby);return}将集合压入到栈顶,集合返回页面的时候,转换成json的形将集合压入到栈顶,集合返回页面的时候,转换成json的形式<result "精确到Session的权限控制(判断Session是否存在publicclassSystemFilterimplementsFilterpublicclassSystemFilterimplementsFilterList<StringlistnewArrayList<String>();publicvoidinit(FilterConfigconfig)throwsServletException } publicvoiddoFilter(ServletRequestreq,ServletResponseres,FilterChainchain)throwsIOException,ServletException{HttpServletRequestrequest=(HttpServletRequest)req;HttpServletResponseresponse=(HttpServletResponse)res; Stringpath= chain.doFilter(request,response);}ElecUserelecUser=chain.doFilter(request,response);}}publicvoiddestroy()}} privatevoidforwordIndexPage(Stringpath,HttpServletRequestrequest)if(path!=null&&path.equals("/index.jsp")){Stringname="";Stringpassword="";Stringchecked=""; s= s!=null:name tryname=URLDecoder.decode(name,"UTF-}catch(UnsupportedEncodingExceptione){}checked=} password= }}}request.setAttribute("name",name);request.setAttribute("password",password);request.setAttribute("checked",checked);}}}自定义过滤器,要求添加到struts2自定义过滤器,要求添加到struts2 问题:不够友好,,最好提示【操作,系统将会5秒后跳转到登录页面】init2 在doFilter的方法重定向到vari=6;vart;function要清除掉setInterval()ontextPathi=i-1//秒数减少timer层 =}}//showTimer()t=window.setInterval(showTimer,1000);注意:SessionSessionSession压力大,系10分钟如果不操作系统,将Session在过滤器中获取登录后存放的SessionSession不为空,则放行,即可以操作定义的业务功能,如果Session为空,则跳转到登录页面。控 的系统必须要存在添加异常处理,见【技术资料\自定义器(实现异常处理+细颗粒权限控制)\异常处理】中的《struts2的器实现异常处理.doc》使用struts2 ntercept()方法定义try…catch异result=actioninvocation.invoke();returnresult;resultreturn"errorMsg";跳转到错误页面。9:细颗粒权限控制(使用struts2的器中的《struts2的器实现细颗粒度权限控制.doc》struts2么不从Sessionmidmidstruts2么不从Sessionmidmid Session,使用struts2 pid(mid=””,pid=””在struts2 pid重点:登录操作,项目中校验和前台校验,hibernate的懒加载处理了解:,记住我1:使用webservice发布系统元数据,调用的过操作步骤【技术资料\webservice技术\axis的jar包中《axis发布, 第一步:使用服务器端提供的接口,生成.wsdl文件第二步:使用.wsdl文件,在电力系统中生成服务器端的代码第三步:使用.wsdl文件(()webserviceweb容器启动的时候( 使用的时候只需要从application对象中获取即可 2:hibernate的二级缓存 hibernate的二级缓存优化。需要引入三个jar包在hibernate需要引入三个jar包在hibernate下能找到在 下能找 <?xml<?xmlversion="1.0"encoding="UTF-<!DOCTYPEhibernate-configuration"-//Hibernate/HibernateConfigurationDTD3.0//EN"开启二级缓存提供二级缓存的供应商启用查询缓存<property<!--<!--加 文件-- <class-cacheusage="read-write" 第三步:在DAOhqlsetCacheable(true)publicpublicList<T>findCollectionByConditionNoPageWithCache(StringfinalObject[]params,Map<String,String>orderby)Stringhql="SELECToFROM"+entityClass.getSimpleName()+"oWHERE1=1";StringorderByHql=this.initOrderByHql(orderby);finalStringfinalHql=hql+condition+List<T>list=HibernateCallback()publicnHibernate(SessionthrowsHibernateException,SQLException{Queryquery=session.createQuery(finalHql);if(params!=null&¶ms.length>0){for(inti=0;i<params.length;i++){query.setParameter(i,params[i]);}}returnquer

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论