spring and spring mvcWord文档格式.docx

上传人:b****2 文档编号:3696794 上传时间:2023-05-02 格式:DOCX 页数:8 大小:20.42KB
下载 相关 举报
spring and spring mvcWord文档格式.docx_第1页
第1页 / 共8页
spring and spring mvcWord文档格式.docx_第2页
第2页 / 共8页
spring and spring mvcWord文档格式.docx_第3页
第3页 / 共8页
spring and spring mvcWord文档格式.docx_第4页
第4页 / 共8页
spring and spring mvcWord文档格式.docx_第5页
第5页 / 共8页
spring and spring mvcWord文档格式.docx_第6页
第6页 / 共8页
spring and spring mvcWord文档格式.docx_第7页
第7页 / 共8页
spring and spring mvcWord文档格式.docx_第8页
第8页 / 共8页
亲,该文档总共8页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

spring and spring mvcWord文档格式.docx

《spring and spring mvcWord文档格式.docx》由会员分享,可在线阅读,更多相关《spring and spring mvcWord文档格式.docx(8页珍藏版)》请在冰点文库上搜索。

spring and spring mvcWord文档格式.docx

springandspringmvc@#@springandspringmvc@#@SpringandSpringMVCIn-DepthAnalysisTheCorepackageisthemostfundamentalpartoftheframeworkandprovidestheDependencyInjectionfeaturesallowingyoutomanagebeancontainerfunctionality.ThebasicconcepthereistheBeanFactory,whichprovidesafactorypatternremovingtheneedforprogrammaticsingletonsandallowingyoutodecoupletheconfigurationandspecificationofdependenciesfromyouractualprogramlogic.OntopoftheCorepackagesitstheContextpackage,providingawaytoaccessbeansinaframework-stylemanner,somewhatresemblingaJNDI-registry.Thecontextpackageinheritsitsfeaturesfromthebeanspackageandaddssupportfortextmessagingusinge.g.resourcebundles,event-propagation,resource-loadingandtransparentcreationofcontextsby,forexample,aservletcontainer.TheDAOpackageprovidesaJDBC-abstractionlayerthatremovestheneedtodotediousJDBCcodingandparsingofdatabase-vendorspecificerrorcodes.Also,theJDBCpackageprovidesawaytodoprogrammaticaswellasdeclarativetransactionmanagement,notonlyforclassesimplementingspecialinterfaces,butforallyourPOJOs(plainoldjavaobjects).TheORMpackageprovidesintegrationlayersforpopularobject-relationalmappingAPIs,includingJDO,HibernateandiBatis.UsingtheORMpackageyoucanuseallthoseO/R-mappersincombinationwithalltheotherfeaturesSpringoffers,likesimpledeclarativetransactionmanagementmentionedbefore.Spring’sAOPpackageprovidesanAOPAlliancecompliantaspect-orientedprogrammingimplementationallowingyoutodefine,forexample,method-interceptorsandpointcutstocleanlydecouplecodeimplementingfunctionalitythatshouldlogicallyspeakingbeseparated.Usingsource-levelmetadatafunctionalityyoucanincorporateallkindsofbehavioralinformationintoyourcode,alittlelike.NETattributes.Spring’sWebpackageprovidesbasicweb-orientedintegrationfeatures,suchasmultipartfunctionality,initializationofcontextsusingservletlistenersandaweb-orientedapplicationcontext.WhenusingSpringtogetherwithWebWorkorStruts,thisisthepackagetointegratewith.Spring’sWebMVCpackageprovidesaModel-View-Controllerimplementationforweb-applications.Spring’sMVCimplementationisnotjustanyimplementation,itprovidesacleanseparationbetweendomainmodelcodeandwebformsandallowsyoutousealltheotherfeaturesoftheSpringFrameworklikevalidation.Spring’swebMVCframeworkisdesignedaroundaDispatcherServletthatdispatchesrequeststohandlers,withconfigurablehandlermappings,viewresolution,localeandthemeresolutionaswellassupportforuploadfiles.ThedefaulthandlerisaverysimpleControllerinterface,justofferingaModelAndViewhandleRequest(request,response)method.Thiscanalreadybeusedforapplicationcontrollers,butyouwillprefertheincludedimplementationhierarchy,consistingof,forexampleAbstractController,AbstractCommandControllerandSimpleFormController.Applicationcontrollerswilltypicallybesubclassesofthose.Notethatyoucanchooseanappropriatebaseclass:

@#@Ifyoudon’thaveaform,youdon’tneedaFormController.ThisisamajordifferencetoStruts.Youcanuseanyobjectasacommandorformobject-there’snoneedtoimplementaninterfaceorderivefromabaseclass.Spring’sdatabindingishighlyflexible,forexample,ittreatstypemismatchesasvalidationerrorsthatcanbeevaluatedbytheapplication,notassystemerrors.Soyoudon’tneedtoduplicateyourbusinessobjects’propertiesasStringsinyourformobjects,justtobeabletohandleinvalidsubmissions,ortoconverttheStringsproperly.Instead,itisoftenpreferabletobinddirectlytoyourbusinessobjects.ThisisanothermajordifferencetoStrutswhichisbuiltaroundrequiredbaseclasseslikeActionandActionForm-foreverytypeofaction.AllyourregisteredbeansandallofSpring’sservicescanbeatyourfingertipsevenwithoutSpring’swebMVC.Springdoesn’tcompetewithStrutsorWebWorkinthisscenario,itjustaddressesthemanyareasthatthepurewebMVCframeworksdon’t,frombeanconfigurationtodataaccessandtransactionhandling.SoyouareabletoenrichyourapplicationwithaSpringmiddletierand/ordataaccesstier,evenifyoujustwanttouse,forexample,thetransactionabstractionwithJDBCorHibernate.FeaturesofSpringMVCSpring’swebmoduleprovidesawealthofuniquewebsupportfeatures,including:

@#@Clearseparationofroles-controller,validator,commandobject,formobject,modelobject,DispatcherServlet,handlermapping,viewresolver,etc.Eachrolecanbefulfilledbyaspecializedobject.SomeofthethebenefitsofusingSpringtocreateyourO/RmappingDAOsinclude:

@#@Easeoftesting.Spring’sinversionofcontrolapproachmakesiteasytoswaptheimplementationsandconfiglocationsofHibernateSessionFactoryinstances,JDBCDataSources,transactionmanagers,andmapperobjectimplementations(ifneeded).Thismakesitmucheasiertoisolateandtesteachpieceofpersistence-relatedcodeinisolation.Commondataaccessexceptions.SpringcanwrapexceptionsfromyouO/Rmappingtoolofchoice,convertingthemfromproprietary(potentiallychecked)exceptionstoacommonruntimeDataAccessExceptionhierarchy.Thisallowsyoutohandlemostpersistenceexceptions,whicharenon-recoverable,onlyintheappropriatelayers,withoutannoyingboilerplatecatches/throws,andexceptiondeclarations.Youcanstilltrapandhandleexceptionsanywhereyouneedto.RememberthatJDBCexceptions(includingDBspecificdialects)arealsoconvertedtothesamehierarchy,meaningthatyoucanperformsomeoperationswithJDBCwithinaconsistentprogrammingmodel.Generalresourcemanagement.SpringapplicationcontextscanhandlethelocationandconfigurationofHibernateSessionFactoryinstances,JDBCDataSources,iBATISSQLMapsconfigurationobjects,andotherrelatedresources.Thismakesthesevalueseasytomanageandchange.Springoffersefficient,easyandsafehandlingofpersistenceresources.Forexample:

@#@RelatedcodeusingHibernategenerallyneedstousethesameHibernateSessionforefficiencyandpropertransactionhandling.SpringmakesiteasytotransparentlycreateandbindaSessiontothecurrentthread,eitherbyusinganexplicit‘template’wrapperclassattheJavacodelevelorbyexposingacurrentSessionthroughtheHibernateSessionFactory(forDAOsbasedonplainHibernate3API).ThusSpringsolvesmanyoftheissuesthatrepeatedlyarisefromtypicalHibernateusage,foranytransactionenvironment(localorJTA).Integratedtransactionmanagement.SpringallowsyoutowrapyourO/Rmappingcodewitheitheradeclarative,AOPstylemethodinterceptor,oranexplicit‘template’wrapperclassattheJavacodelevel.Ineithercase,transactionsemanticsarehandledforyou,andpropertransactionhandling(rollback,etc)incaseofexceptionsistakencareof.Asdiscussedbelow,youalsogetthebenefitofbeingabletouseandswapvarioustransactionmanagers,withoutyourHibernate/JDOrelatedcodebeingaffected:

@#@forexample,betweenlocaltransactionsandJTA,withthesamefullservices(suchasdeclarativetransactions)availableinbothscenarios.Asanadditionalbenefit,JDBC-relatedcodecanfullyintegratetransactionallywiththecodeyouusetodoO/Rmapping.Thisisusefulfordataaccessthat’snotsuitableforO/Rmapping,suchasbatchprocessingorstreamingofBLOBs,whichstillneedstosharecommontransactionswithO/Rmappingoperations.Toavoidvendorlock-in,andallowmix-and-matchimplementationstrategies.WhileHibernateispowerful,flexible,opensourceandfree,itstillusesaproprietaryAPI.FurthermoreonecouldarguethatiBATISisabitlightweight,althoughit’sexcellentforuseinapplicationthatdon’trequirecomplexO/Rmappingstrategies.Giventhechoice,it’susuallydesirabletoimplementmajorapplicationfunctionalityusingstandardorabstractedAPIs,incaseyouneedtoswitchtoanotherimplementationforreasonsoffunctionality,performance,oranyotherconcerns.Forexample,Spring’sabstractionofHibernatetransactionsandexceptions,alongwithitsIoCapproachwhichallowsyoutoeasilyswapinmapper/DAOobjectsimplementingdataaccessfunctionality,makesiteasytoisolateallHibernate-specificcodeinoneareaofyourapplication,withoutsacrificinganyofthepowerofHibernate.HigherlevelservicecodedealingwiththeDAOshasnoneedtoknowanythingabouttheirimplementation.Thisapproachhastheadditionalbenefitofmakingiteasytointentionallyimplementdataaccesswithamix-and-matchapproach(i.e.somedataaccessperformedusingHibernate,andsomeusingJDBC,othersusingiBATIS)inanon-intrusivefashion,potentiallyprovidinggreatbenefitsintermsofcontinuingtouselegacycodeorleveragingthestrengthofeachtechnology.TheSpringtransactionabstractionSpringprovidesaconsistentabstractionfortransactionmanagement.ThisabstractionisoneofthemostimportantofSpring’sabstractions,anddeliversthefollowingbenefits:

@#@ProvidesaconsistentprogrammingmodelacrossdifferenttransactionAPIssuchasJTA,JDBC,Hibernate,iBATISDatabaseLayerandJDO.Providesasimpler,easiertouse,APIforprogrammatictransactionmanagementthanmostofthesetransactionAPIsIntegrateswiththeSpringdataaccessabstractionSupportsSpringdeclarativetransactionmanagementTraditionally,J2EEdevelopershavehadtwochoicesfortransactionmanagement:

@#@touseglobalorlocaltransactions.Globaltransactionsaremanagedbytheapplicationserver,usingJTA.Localtransactionsareresource-specific:

@#@forexample,atransactionassociatedwithaJDBC

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 法律文书 > 调解书

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2