




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
控制反轉(zhuǎn):應(yīng)用本身不負(fù)責(zé)依賴對象的創(chuàng)建及依賴對象的創(chuàng)建及是由外部窗口負(fù)spring可以使用容器提供的眾多服務(wù),如:事務(wù)管理服務(wù)、消息服務(wù)、JMS容器提供了AOP技術(shù),利用它很容易實現(xiàn)如權(quán)限,運行期等功能 如果使用了切面編程,還需下列jar文件:lib\aspectj\aspectjweaver.jaraspectjrt.jar如果使用了jsr-250jarpublicvoidtestEnv(){ApplicationContextctx=new}說明:beans.xml可以在類路徑下進行配置,也可以在具體的 件,也可以是多個配置文件組成String數(shù)組傳入。publicinterfaceUserDao}publicclassUserDaoImplimplementspublicvoidsave(){}}在 <beansxmlns="xmlns:xsi="<beanid="userDaoImpl"class="com.asm.dao.impl.UserDaoImpl"說明:beanjavaid補充:讓xml配置文件在編譯時提示[windows][preferences][myeclipse][filesandeditors][xml][xmlcatalog]點add,在出現(xiàn)窗口的location中選“filesystem”,然后在spring解 為:JunitSpringEnvTestpublicvoidbase(){ApplicationContextctx=newUserDaouserDao=(UserDao)ctx.getBean("userDaoImpl");}三種bean除了上面使用的類直接生成方式,還有beanbeanbean<beanid="userDaoImpl2"class="com.asm.dao.impl.UserDaoImplFactory"publicclassUserDaoImplFactorypublicstaticUserDaoImplreturnnew}}<beanid="factory"<beanid="userDaoImpl3"factory-publicclassUserDaoImplFactory2{publicUserDaoImplgetUserDaoImpl(){returnnewUserDaoImpl();}}beansingleton:返回bean(無狀態(tài)bean使用此作用域request、session、globalsessionwebbean什么時候初始化bean時才初始化,可以使用lazy-init="true"補充:如果希望希望該配置文件中的所有bean都延遲初始化,則應(yīng)在beans根結(jié)點中使用lazy-init="true"。時,在調(diào)用initbeandestroy(ctx.closebeanscope設(shè)為prototype時,當(dāng)ctx.close時,destroy方法不會被調(diào)用)屬性注入Setter<beanid="userServiceBean"<propertyname="id"<propertyname="username"value="某<propertyname="userDao"<property<beanid="temp"<property<property<property<entrykey="onevalue="一<entrykey="twovalue="二<entrykey="threevalue="三<property<prop<prop<prop注意:在相應(yīng)的字段上一定要有setter ="true"id="parent"<propertyname="username"value="某<beanid="XXX"class="com.asm.vo.User"<propertyname="password"相當(dāng)于在XXXbean實例中也有username<beanid="userServiceBean2"<constructor-argindex="0value="李某某<constructor-argindex="1"ref="userDaoImpl"<constructor-arg{}<beansxmlns="xmlns:xsi="">Resource拷貝上一個項目為spring_02_annotationUserServiceBeanpublicclassUserServiceBean{@Resource(name="userDaoImpl")privateUserDaouserDao;privateUserDaouserDao2;publicvoidsetUserDao2(UserDaouserDao2)this.userDao2=}publicvoidtest(){}}然后在bean.xml<beanid="userDaoImpl"class="com.asm.dao.impl.UserDaoImpl"<beanid="userServiceBean"class="com.asm.service.UserServiceBean"/>privateUserDaouserDao3;Autowired實例,可以使用QualifierRequiredtrue它也實用于setter方法。它屬于spring特有的注解,Autowired默認(rèn)按類型裝配。<beanid="userServiceBean2"class="com.asm.service.UserServiceBean2autowire="byType"/> ponent-scanbase-package="包名"/>便可以自動管理指定包名及子下標(biāo)住了@service(業(yè)務(wù)層組件)、@controller(控制層組件)、@repository(數(shù)據(jù)訪組件或@coponen泛指組的類把它們一個實例ben,相當(dāng)在beansxml中配置了<bean元素需要明的是使了此配同意味著還了注配置的理器所以在這些中用到注解配時并不要再配置tnt-f。為什么提自動掃管理在一比較大項目中涉及到的ben實例有很多如依次對每個bea實例進配置,但配置容繁瑣而配置文件會顯得亂。因此pring提出了自掃描bea,它依在 文中指的名和類中記的 pnent系注解。<beansxmlns="xmlns:xsi="xmlns:context=".> ponent-scanbase- ponent-scanbase-說明:以上的配置會自動管理serviceimplcomponent ponent-scanbase-下面以UserServiceBeanpublicclassUserServiceBean{@Resource(name="userDaoImpl")privateUserDaouserDao;privateUserDaouserDao2;@Autowired(required=true)privateUserDaouserDao3;publicvoidsetUserDao2(UserDaouserDao2)this.userDao2=}publicUserServiceBean()}publicvoidinit(){System.out.println("initmethodiscalled");}publicvoidtest(){//userDao3.save();}}publicclassAutoScanTest{publicvoidbase(){ApplicationContextctx=newUserServiceBeanudb=(UserServiceBean)ctx.getBean("usb");}}五、AOP技術(shù)publicinterfaceUserDao}publicclassUserDaoImpimplementsUserDaoprivateStringpublicUserDaoImp()}publicUserDaoImp(Stringusername)this.username=}publicStringgetUsername()}publicvoidsave()System.out.println("savemethodiscalled:"+}publicvoidupdate()System.out.println("updatemethodiscalled"+}}需求如下:如果實現(xiàn)類的username!=null,才可以調(diào)用save與update方法,為null則不能調(diào)用。當(dāng)然要解決此問題,可以在saveupdate部進行判斷,代碼則失去了靈活性,如果以后的需求改變,比如變成username.equals則又要在update/savesave/update這樣的方法很多,這樣求來一些業(yè)務(wù)方法,這種編程問題稱之為橫切性關(guān)注點。動態(tài)實現(xiàn)publicclassProxyFactoryimplementsInvocationHandlerprivateObjectpublicObjectcreateUserDaoImp(Objecttarget)this.target=this.target.getClass().getInterfaces(),this);}publicObjectinvoke(Objectproxy,Methodmethod,Object[]throwsThrowableUserDaoImpudi=(UserDaoImp)target;Objectresult=null;if(udi.getUsername()!=null){result=method.invoke(target,args);}}}簡析動態(tài):此類根據(jù)傳遞的target對象來生成此目標(biāo)對象的對象,需要強調(diào)的是動態(tài)技術(shù)所要的對象必須實現(xiàn)一個接口。newProxyInstance參數(shù)說明:第一的對象要執(zhí)行方法時就是依靠這個回調(diào)對象的invoke方法來進行目標(biāo)對象的方法回調(diào)。關(guān)于動態(tài)的其它細(xì)節(jié)不在此討論。建立junit測試代碼,內(nèi)容如下:publicclassAopProxyTest@Test//用戶名為空,不執(zhí)行方法publicvoidtestProxy(){ProxyFactorypf=newUserDaoud=(UserDao)pf.createUserDaoImp(newUserDaoImp());}@Test用戶名為不為空,才執(zhí)行savepublicvoidtestProxy2(){ProxyFactorypf=newProxyFactory();UserDaoud=(UserDao)pf.createUserDaoImp(newUserDaoImp(""));}}cglibJDK的Proxy實現(xiàn)要求被的目標(biāo)對象必須實現(xiàn)一個接口而如果目標(biāo)對象沒有實現(xiàn)接口則不能使用Proxy來。其實也可以借助cglib來實現(xiàn)。操作步驟如下publicclassCglibFactoryimplementsMethodInterceptorprivateObjectpublicObjectcreateUserDaoImp2(Objecttarget)this.target=Enhancerenhancer=newEnhancer();方法進行覆蓋,但在覆蓋方法時會添加一些代碼。enhancer.setCallback(this);//回調(diào)器}publicObjectintercept(Objectproxy,Methodmethod,Object[]args,MethodProxymethodProxy)throwsThrowableUserDaoImp2udi=(UserDaoImp2)target;Objectresult=null;if(udi.getUsername()!=null){result=methodProxy.invoke(target,}catch(Exceptione){}finally}}}}aop基于springAOP步驟一、導(dǎo)入spring(包括切面及注解包)publicclassTheInterceptor@Pointcut("execution(*//一個切入點(第一個*后要留一個空格privatevoidanyMethod()}@Before("anyMethod()前置通知publicvoidbefore(){}publicvoidafterReturning(){}}簡析:Aspect注解此類為一個切面類,Pointcut注解用來一個切入點,括號中的參數(shù)是切入點的表達(dá)式,這里的表達(dá)式的意思是對UserDaoImp類的所有方法進行。關(guān)于切入點表達(dá)式后面會有詳細(xì)的說明。anyMethod步驟三、beans.xml<beansxmlns="xmlns:xsi="xmlns:context="xmlns:aop=".<aop:aspectj-autoproxy開啟切面編程功能<beanid="userDaoImp"class="com.asm.dao.impl.UserDaoImp"<beanid="theInterceptor"class="com.asm.dao.impl.factory.TheInterceptor"/>publicvoidbase(){ApplicationContextctx=new//UserDaoImpudii=(UserDaoImp)ctx.getBean("userDaoImp");UserDaoud=(UserDao)ctx.getBean("userDaoImp");}—UserDaoImp時,它實際上獲取的是此對象的一個對象,而在spring中對對象理有如下原則:(1)如果要的對象實現(xiàn)了接口,則會按照Proxy的方式來產(chǎn)生對補充:測試被對象未實現(xiàn)接口時,spring切面技術(shù)的應(yīng)用。@Pointcut("execution(*說明:impl包下的所有類所有方法<beanid="userDaoImp2"class="com.asm.dao.impl.UserDaoImp2"publicvoidbase2(){ApplicationContextctxnewUserDaoImp2udi2=(UserDaoImp2)ctx.getBean("userDaoImp2");}說明:UseDaoImp2未實現(xiàn)任何接口,因此在spring中利用切面技術(shù)來管理此類使用的技術(shù)實質(zhì)是cglib的動態(tài)方式,所以產(chǎn)生的對象實質(zhì)是被對象的一個子采取兩種方式來產(chǎn)生對象。(4)在xml文件中啟用<aop:aspectj-autoproxy/>@After("anyMethod最終通知publicvoidafter(){}為了演示此實例,我們在UseDaoImp中增加如下代碼以拋出異常:inti=1/0;在然后在切面類TheInterceptor中增加如下代碼:@AfterThrowing("anyMethod()")//例外通知publicvoidAfterThrowing(){}@Around("anyMethod()publicObjectaround(ProceedingJoinPointpjpthrowsThrowable//ifObjectresult=}處理代碼起作用必須調(diào)用ceed方法。補充:環(huán)繞通知通常可以用來測試方法的時間,在ceed前獲取一個時間,在ceed方法后再獲取一個時間。最Stringadd(StringpublicStringadd(Stringname)System.out.println("addmethodiscalled["+name+"return"添加成功}@Before("anyMethod(&&args(name前置通知,只針對UseDaoImp的addpublicvoidbeforeAdd(Stringname){System.out.println("前置通知name);}:說明置通知的方法中有一個參數(shù),然后再把此參數(shù)作為條件(即是說帶有一:publicvoidadvieeTest(){ApplicationContextctx=newUserDaoud=(UserDao)ctx.getBean("userDaoImp");}@AfterReturning(pointcut="anyMethod()",returning=//后置通知,返回結(jié)果,針對UserDaoImp的getUsername()方法publicvoidafterReturningRes(Stringresult){System.out.println("后置通知,返回結(jié)果:"+result);}說明:afterReturningRes方法的參數(shù)就是要返回的參數(shù)類型,returning標(biāo)記的就publicvoidcatchException(Exceptione){}步驟一、TheInterceptorX類為TheInterceptorXML,并去掉所有注解。<aop:aspectj-autoproxy開啟切面編程功能<beanid="userDaoImp"class="com.asm.dao.impl.UserDaoImp"<beanid="aspectBean"class="com.asm.dao.impl.factory.TheInterceptorXML"/><aop:aspectid="asp"ref="aspectBean">--一個切面<aop:pointcutid="thecut"--一個切入expression="execution(*com.asm.dao.impl.UserDaoImp.*(..))"<aop:after-returningpointcut-ref="thecut"method="afterReturningRes"returning="result"/><aop:after-throwingpointcut-ref="thecut"method="catchException"throwing="e"/><aop:afterpointcut-ref="thecut"method="after"<aop:beforepointcut-ref="thecut"method="before"publicvoidadvieeTest(){ApplicationContextctx=UserDaoud=(UserDao)ctx.getBean("userDaoImp");}返回值:可以是*,說明任何方法。Java.lang.String(全名),返回值為String(java.lang.String方法選擇略)返回值為String類型的方(!void方法選擇略)返回值非空的方(*com.asm..*.*(..))com.asm包及子包下每個類的全部方(*com.asm.*.*(..))com.asm包下每個類的全部方法(*com.asm.User.*(..))asm包下User類的所有方法(*com.asm.User.*User類中第一個參數(shù)為String,后面參面向切面的常見應(yīng)用(如權(quán)限)、spring的aop依賴兩種方式實現(xiàn)(依被的象是否實現(xiàn)接口而定XML(依要被的類只能是通過Spring容器獲取)、切入點的格式。六、與JDBC建立spring_05_integrationJdbc項目,此項目使用dbcp作為數(shù)據(jù)源來整合JDBC技術(shù)。因此除了springjardbcpjar:commons-dbcp-1.2.2.jar所依賴的兩個apache開源jar包:commons-coll 于涉及到數(shù)據(jù)庫操作,還應(yīng)導(dǎo)入數(shù)據(jù)庫驅(qū)動包,這里選擇的是mySQL驅(qū)動。<beansxmlns="xmlns:xsi="xmlns:aop="xmlns:tx="xmlns:context=".><bean <propertyname="driverClassName"value="com.mysql.jdbc.Driver"<propertyname="url"value="jdbc:mysql://localhost:3306/sjdbc"<propertyname="username"value="root"<propertyname="password"value="123456"<propertyname="initialSize"value="2"<propertyname="maxActive"value="100"<propertyname="maxIdle"value="2"<propertyname="minIdle"value="1"<beanid="txManager"<propertyname="dataSource"ref="theDatasource"<tx:annotation-driventransaction-manager="txManager"publicinterfaceUserDao{voidsave(Useruser);voiddelete(Useruser);voidupdate(Useruser);Userget(intid);}publicclassUserDaoImpimplementsUserDaoprivateJdbcTemplatepublicvoidsetDatasouce(DataSourcedatasource){jdbcTemplate=newJdbcTemplate(datasource);}publicvoiddelete(Useruser)jdbcTemplate.update("deletefromuserwhereid=?",new{user.getId()newint[]{java.sql.Types.INTEGER}publicUserget(intid)return(User)jdbcTemplate.queryForObject("select*fromuserwhereid=?",newObject[]{id},newint[]{java.sql.Types.INTEGERnewRowMapper()publicObjectmapRow(ResultSetrs,intarg1)SQLExceptionUseruser=newUser();}}publicList<User>getUsers()return(List<User>)jdbcTemplate.query("select*fromuser",RowMapper()publicObjectmapRow(ResultSetrs,intarg1)SQLExceptionUseruser=newUser();}}publicvoidsave(Useruser)jdbcTemplate.update("insertintouser(name)values(?)",Object[]{user.getName()newint[]{java.sql.Types.VARCHAR}publicvoidupdate(Useruser)jdbcTemplate.update("updateusersetname=?whereid=?",Object[]{user.getId()},newint[]{java.sql.Types.VARCHAR,java.sql.Types.INTEGER});}}<beanid="userDaoImp"<propertyname="datasouce"ref="theDatasource"UsrDaoIm(1)bea實例納入pringdaasourca對象的初始(該類CRDSpingmt對象來簡化了CRD操作,在spring11.2..節(jié)對JdcTemplae(3)ntabeans.ml配置的<tx:annotation-driventransaction-manager="txManager管理publicclassTestSJprivateUserDaoud=(UserDao);publicstaticvoidmain(String[]args){TestSJsj=newTestSJ();}publicvoidsave(){UserusernewUser();}publicvoiddelete(){Useruser=newUser();}}jdbcTemplate.update("deletefromuserwhereid=?",new{user.getId()},newint[]{java.sql.Types.INTEGERjdbcTemplate.update("deletefromuserwherespring默認(rèn)的事務(wù)管理方式:運行期異常進行事務(wù)回滾,非運行期異常不進行事務(wù)回滾。因此增加上面的代碼后,會出現(xiàn)ArithmeticExceptiondelete方法中的數(shù)據(jù)庫操作都會進行回滾,因而id=1和2這兩條記錄都不會被刪除。如果把UseDaoImp類前標(biāo)記@Transactional的注解去掉,id=1的記錄會被刪除,因為失去了spring小結(jié)spring事務(wù):(1)在beans.xml事務(wù)管理器(比如和JPA集成的事務(wù)管理器等),這些事務(wù)管理器類都繼承自transaction-manager="txManager);被管理的類打上事務(wù)注解標(biāo)記。(4)除REQUIREDREQUIRESNEWSUPPORTSNOT_SUPPORTED業(yè)務(wù)方法不需要事務(wù),如果方法沒有關(guān)聯(lián)到一個事務(wù),容器不會為它NEVERMANDATORYNESTED則按REQIIRED屬性執(zhí)行。需要注意的是此配置只對DataSourceTransactionManager事務(wù)管理器生效。法前會有一個設(shè)定了詳細(xì)屬性的@Transactional注解。比如:離級別。(具體的事務(wù)級別分析在些略過,可以參看網(wǎng)絡(luò)資源及相關(guān)文檔)超時屬性timeout:int擴展:抽取dpcp <bean <propertyname="driverClassName"value="${driverClassName}"<propertyname="url"value="${url}"<propertyname="xxxvalue="${perties配置文件中的鍵注意的是使用${}來獲取值,必須把propertiesspring成功通過${}來獲取相應(yīng)的值,還應(yīng)beans.xml中增加如下內(nèi)容:<context:property-placeholderlocation="classpath:perties而要想使用<context:XXX/>還應(yīng)在beans.xml增加名稱空間:和schema關(guān)于這里的名稱空間及schemaA2.8基于XML為expression="execution(*com.asm.dao.impl.UserDaoImp2.*(..))"<aop:advisoradvice-ref="txAdvice"pointcut-ref="txPointcut"<tx:methodname="get*"read-only="true"<tx:methodname="*"/>-->所有方解析:根據(jù)txManagertxAdvice。而<tx:method>中的name屬性指定方法名(可以使用通配符),其它屬性就好比注解的屬性配置(可參步驟四、把UserDaoImp2springbeansXML.xml<beanid="userDaoImp2"<propertyname="datasouce"ref="theDatasource"5.總結(jié)與JDBCxmlapo(3)涉及到事務(wù)的類必須納入spring(4)強調(diào):不論是基于注解還是基于xml配置實現(xiàn)事務(wù),都要依賴于動態(tài)技術(shù)。以UserDaoImp說明,它實現(xiàn)了接口,所以它的對象實質(zhì)是一個接口對象,因而通過getBean獲取的UseDaoImp實質(zhì)上是一個接口對象,所以特別要注意類型轉(zhuǎn)換(參六.2.步驟四.說明)。(5)為了簡化CRUD我們通常會使用springJdbcTemplate七、SSH集成實例建立spring_06_SSHstruts1.x、hibernate、springjar較清楚的認(rèn)識。下面列表展示了三個框架所用到的jar包。hibernate3.3jarantlr-2.7.6.jar開源語法分析commons-collections-3.1.jarCommons(lib\required)dom4j-1.6.1.jarxml解析類庫(lib\required)javassist-3.9.0.GA.jarjava(lib\required)jta-1.1.jar事務(wù)處理api(lib\required)slf4j-api-1.5.8.jar(lib\required)-->用log4jhibernate3.jarehcache-1.2.3.jarSpring2.5安裝包所用的jar包: mons\commons-logging.jar、c lib\log4j\log4j-1.2.15.jar供sr與hibernate使用的日志記錄jarlib\slf4j\slf4j-log4j12-1.5.0.jarjarlog4j.jarslf4jstruts1.10jar 下的所有jar包。但為了避免jar包,不要導(dǎo)入antlr.jar(hibernatejar包說明:綠色字樣是框架所需的一些基本包。hibernate的開發(fā)jar包主要集中在 和jar包,還需要特別說明的是它的日志包問題:hibernate使用了log4jslf4j-log4j12-1.5.8.jar和springlog4jlog4jspring的lib子中找到。Springjar包外,還增加了dbcp關(guān)的包,需要說明的是連接池的基本包為:dbcp、pool、collections(在hibernate導(dǎo)入)。為了與strus相結(jié)合,還增加了一個spring-webmvc-struts.jar包。的包都可以從spring提供的lib中查詢。集成對于框架的集成最好的方式是分布集成,比如這里先集成spring+hibernatepublicinterfaceUserService voidsave(User voiddelete(Integer voidupdate(User UsergetUser(Integerid); List<User>}publicclassUserServiceBeanimplementsUserService{privateSessionFactorysf;publicvoidsave(Useruser){}}的<bean <propertyname="driverClassName"value="com.mysql.jdbc.Driver"<propertyname="url"value="jdbc:mysql://localhost:3306/ssh"<propertyname="username"value="root"<propertyname="password"value="123456"<beanid="txManager"<propertyname="sessionFactory"ref="sessionFactory"<tx:annotation-driventransaction-manager="txManager"<beanid="sessionFactory"<propertyname="dataSource"ref="theDatasource"<propertyname="map<property<propertyname="configLocation"value="hibernate.cfg.xml"<beanid="userServiceBean"class="com.asm.service.impl.UserServiceBean"/>publicclassUserServiceTest{privatestaticUserServiceus;publicstaticvoidsetUpBeforeClass()throwsException{ApplicationContextctx=newus=(UserService)ctx.getBean("userServiceBean");}數(shù)據(jù)源SessionFactory被包裝UserServiceBean的sf屬性publicvoidtestSave()us.save(newUser("李某某}}集成struts<?xmlversion="1.0"encoding="ISO-8859-1"<!DOCTYPEstruts-config"-//ApacheSoftwareFoundation//DTDStrutsConfiguration1.3//EN"""> <actionpath="/list"<forwardpublicclassUserActionextendsAction{publicActionForwardexecute(ActionMapmap,ActionFormform,HttpServletRequestrequest,HttpServletResponseresponse)throwsException{WebApplicationContextctx=UserServiceus=(UserService)ctx.getBean("userServiceBean");List<User>users=us.getUsers();}}此器的作用就是在啟動時把spring容器進行實例化,并把spring容器實例WebApplicationContext對象放到applicationONTEXT_ATTRIBUTE,springWebApplicationContext過保存的名字來獲取WebApplicationContext對象,但是為了方便,spring提供一具類WebApplicationContextUtils來獲取此對象,關(guān)于這個工具類的使用,在UserAction就是使用了此工具類來獲取spring容器實例。保存一個List<User>對象<c:forEachitems="${users}"${user.id}--${改進集成strutsprivateUserServiceuserService;publicActionForwardexecute(ActionMapmap,ActionFormform,HttpServletRequestrequest,HttpServletResponseresponse)throwsException{request.setAttribute("users",returnmap}<beanname="/list"o的t屬性值相同()。v的處理器類。.中的nv最終其實是實<set-propertyproperty="processorClass"<controllerprocessorClass=所以我們可以在spring容器的beans.xml中的sessionFactorybean實例的cache.use_second_level_cache=true-->開啟二級緩存hibernate.cache.use_query_cache=false-->不使用查詢緩存r-->第緩存實現(xiàn) maxElementsInMemory內(nèi)存中最大允許存在的對象數(shù)量eternal設(shè)置緩存中的對象是否不過期overflowToDisk把溢出的對象存放到硬盤上diskPersistent當(dāng)jvm結(jié)束是是否持久化對象diskExpiryThreadIntervalSeconds指定專門用于清除過期對象的線程的輪<diskStore<defaultCachemaxElementsInMemory="1000"list.do請根據(jù)list.do的請求,分析出在beans.xml中存bean實例,然后把請求交給這個bean實例處Springbean實例說明了為什么要在beans.xml配置的UserAction的名字為“/list”<cachename="com.asm.entity.User"maxElementsInMemory="100"overflowToDisk="true"timeToIdleSeconds="300"timeToLiveSeconds="600"diskPersistent="false"/> <cacheusage="read-write"regin>來和ehcache.xml中的<cachename>關(guān)聯(lián)。publicvoidtestGetUser(){}catch(InterruptedExceptione){}}6.框架中,我們把配置的*.do的請求會被ActionServlet到,而ActionServlet時用到的默認(rèn)編碼為ISO8859-1,即是說設(shè)置了request.setCharacterEncoding充ActionFormActionForm*.doAction,而ActionActionForm需把spring提供的一個過濾器類配置到web.xml中,即增加如下代碼:在以前我們是自己編寫此filterspring關(guān)于這里的亂碼問題可參“struts1.x深入學(xué)習(xí)筆記-四、2.步驟五.問題”。SpringOpenSessionInViewfilter八、SSJhibernate包hibernate注解包hibernate- Hibernate針對JPA的實現(xiàn)包Hibernate-上面列舉的jar(基于hibernateJPA)+SSHjar集成建立spring_07_SSJjaJPA步驟一、搭建JPA<persistencexmlns="h <persistence-unitname="jpaDemo"<propertyname="hibernate.dialect"value="org.hibernate.dialect.MySQL5Dialect"/><propertyname="hibernate.hbm2ddl.auto"value="update"<pro
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025-2030年中國硅膠及硅膠制品市場運營狀況及投資戰(zhàn)略研究報告
- 2025-2030年中國真空保溫杯行業(yè)運行現(xiàn)狀及投資發(fā)展前景預(yù)測報告
- 2025年安徽省建筑安全員-A證考試題庫附答案
- 泰山科技學(xué)院《VI設(shè)計》2023-2024學(xué)年第二學(xué)期期末試卷
- 2021情報學(xué)情報檢索學(xué)試題
- 吉林城市職業(yè)技術(shù)學(xué)院《納米材料制備技術(shù)》2023-2024學(xué)年第二學(xué)期期末試卷
- 2024-2025學(xué)年天津市濱海新區(qū)田家炳中學(xué)高一上學(xué)期12月月考?xì)v史試卷
- 汝州職業(yè)技術(shù)學(xué)院《通信原理與通信技術(shù)》2023-2024學(xué)年第二學(xué)期期末試卷
- 2025青海省建筑安全員C證考試題庫
- 天津師范大學(xué)津沽學(xué)院《招聘與甄選》2023-2024學(xué)年第二學(xué)期期末試卷
- 2025年中國聯(lián)通上海市分公司招聘130人高頻重點模擬試卷提升(共500題附帶答案詳解)
- 2025年河南質(zhì)量工程職業(yè)學(xué)院高職單招職業(yè)技能測試近5年??及鎱⒖碱}庫含答案解析
- 2025年江西生物科技職業(yè)學(xué)院高職單招職業(yè)技能測試近5年??及鎱⒖碱}庫含答案解析
- 2024-2025學(xué)年第二學(xué)期學(xué)校全面工作計劃
- 2025年中國spa行業(yè)市場全景分析及投資前景展望報告
- GB 45187-2024墜落防護動力升降防墜落裝置
- 2024年青島港灣職業(yè)技術(shù)學(xué)院高職單招數(shù)學(xué)歷年參考題庫含答案解析
- 《信息技術(shù)(拓展模塊)》高職全套教學(xué)課件
- 環(huán)保行業(yè)環(huán)保管理制度環(huán)保責(zé)任落實制度
- 2025年山東菏投建設(shè)集團招聘筆試參考題庫含答案解析
- 市政質(zhì)量員繼續(xù)教育考試題庫集(含答案)
評論
0/150
提交評論