计算机专业论文译文Spring框架Word格式.docx
《计算机专业论文译文Spring框架Word格式.docx》由会员分享,可在线阅读,更多相关《计算机专业论文译文Spring框架Word格式.docx(10页珍藏版)》请在冰豆网上搜索。
TheORMpackageprovidesintegrationlayersforpopularobject-relationalmappingAPIs,includingJDO,HibernateandiBatis.UsingtheORMpackageyoucanuseallthoseO/R-mappersincombinationwithalltheotherfeaturesSpringoffers,likesimpledeclarativetransactionmanagementmentionedbefore.
Spring'
sAOPpackageprovidesanAOPAlliancecompliantaspect-orientedprogrammingimplementationallowingyoutodefine,forexample,method-interceptorsandpointcutstocleanlydecouplecodeimplementingfunctionalitythatshouldlogicallyspeakingbeseparated.Usingsource-levelmetadatafunctionalityyoucanincorporateallkindsofbehavioralinformationintoyourcode,alittlelike.NETattributes.
sWebpackageprovidesbasicweb-orientedintegrationfeatures,suchasmultipartfunctionality,initializationofcontextsusingservletlistenersandaweb-orientedapplicationcontext.WhenusingSpringtogetherwithWebWorkorStruts,thisisthepackagetointegratewith.
sWebMVCpackageprovidesaModel-View-Controllerimplementationforweb-applications.Spring'
sMVCimplementationisnotjustanyimplementation,itprovidesacleanseparationbetweendomainmodelcodeandwebformsandallowsyoutousealltheotherfeaturesoftheSpringFrameworklikevalidation.
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.
ComparedtoWebWork,Springhasmoredifferentiatedobjectroles.ItsupportsthenotionofaController,anoptionalcommandorformobject,andamodelthatgetspassedtotheview.Themodelwillnormallyincludethecommandorformobjectbutalsoarbitraryreferencedata.Instead,aWebWorkActioncombinesallthoserolesintoonesingleobject.WebWorkdoesallowyoutouseexistingbusinessobjectsaspartofyourform,butonlybymakingthembeanpropertiesoftherespectiveActionclass.Finally,thesameActioninstancethathandlestherequestisusedforevaluationandformpopulationintheview.Thus,referencedataneedstobemodeledasbeanpropertiesoftheActiontoo.Thesearearguablytoomanyrolesforoneobject.
sviewresolutionisextremelyflexible.AControllerimplementationcanevenwriteaviewdirectlytotheresponse,returningnullasModelAndView.Inthenormalcase,aModelAndViewinstanceconsistsofaviewnameandamodelMap,containingbeannamesandcorrespondingobjects(likeacommandorform,containingreferencedata).Viewnameresolutionishighlyconfigurable,eitherviabeannames,viaapropertiesfile,orviayourownViewResolverimplementation.TheabstractmodelMapallowsforcompleteabstractionoftheviewtechnology,withoutanyhassle.Anyrenderercanbeintegrateddirectly,whetherJSP,Velocity,oranyotherrenderingtechnology.ThemodelMapissimplytransformedintoanappropriateformat,suchasJSPrequestattributesoraVelocitytemplatemodel..
PluggabilityofotherMVCimplementations
ThereareseveralreasonswhysomeprojectswillprefertouseotherMVCimplementations.Manyteamsexpecttoleveragetheirexistinginvestmentinskillsandtools.Inaddition,thereisalargebodyofknowledgeandexperienceavalailablefortheStrutsframework.Thus,ifyoucanlivewithStruts'
architecturalflaws,itcanstillbeaviablechoicefortheweblayer.ThesameappliestoWebWorkandotherwebMVCframeworks.
Ifyoudon'
twanttouseSpring'
swebMVC,butintendtoleverageothersolutionsthatSpringoffers,youcanintegratethewebMVCframeworkofyourchoicewithSpringeasily.SimplystartupaSpringrootapplicationcontextviaitsContextLoaderListener,andaccessitviaitsServletContextattribute(orSpring'
srespectivehelpermethod)fromwithinaStrutsorWebWorkaction.Notethattherearen'
tany"
plugins"
involved,sonodedicatedintegrationisnecessary.Fromtheweblayer'
spointofview,you'
llsimplyuseSpringasalibrary,withtherootapplicationcontextinstanceastheentrypoint.
AllyourregisteredbeansandallofSpring'
sservicescanbeatyourfingertipsevenwithoutSpring'
swebMVC.Springdoesn'
tcompetewithStrutsorWebWorkinthisscenario,itjustaddressesthemanyareasthatthepurewebMVCframeworksdon'
t,frombeanconfigurationtodataaccessandtransactionhandling.SoyouareabletoenrichyourapplicationwithaSpringmiddletierand/ordataaccesstier,evenifyoujustwanttouse,forexample,thetransactionabstractionwithJDBCorHibernate.
FeaturesofSpringMVC
swebmoduleprovidesawealthofuniquewebsupportfeatures,including:
Clearseparationofroles-controller,validator,commandobject,formobject,modelobject,DispatcherServlet,handlermapping,viewresolver,etc.Eachrolecanbefulfilledbyaspecializedobject.
PowerfulandstraightforwardconfigurationofbothframeworkandapplicationclassesasJavaBeans,includingeasyreferencingacrosscontexts,suchasfromwebcontrollerstobusinessobjectsandvalidators.
Adaptability,non-intrusiveness.Usewhatevercontrollersubclassyouneed(plain,command,form,wizard,multi-action,oracustomone)foragivenscenarioinsteadofderivingfromasinglecontrollerforeverything.
Reusablebusinesscode-noneedforduplication.Youcanuseexistingbusinessobjectsascommandorformobjectsinsteadofmirroringtheminordertoextendaparticularframeworkbaseclass.
Customizablebindingandvalidation-typemismatchesasapplication-levelvalidationerrorsthatkeeptheoffendingvalue,localizeddateandnumberbinding,etcinsteadofString-onlyformobjectswithmanualparsingandconversiontobusinessobjects.
Customizablehandlermappingandviewresolution-handlermappingandviewresolutionstrategiesrangefromsimpleURL-basedconfiguration,tosophisticated,purpose-builtresolutionstrategies.ThisismoreflexiblethansomewebMVCframeworkswhichmandateaparticulartechnique.
Flexiblemodeltransfer-modeltransferviaaname/valueMapsupportseasyintegrationwithanyviewtechnology.
Customizablelocaleandthemeresolution,supportforJSPswithorwithoutSpringtaglibrary,supportforJSTL,supportforVelocitywithouttheneedforextrabridges,etc.
AsimplebutpowerfultaglibrarythatavoidsHTMLgenerationatanycost,allowingformaximumflexibilityintermsofmarkupcode.
DataAccessusingO/RMappers
SpringprovidesintegrationwithHibernate,JDO,OracleTopLink,ApacheOJBandiBATISSQLMaps:
intermsofresourcemanagement,DAOimplementationsupport,andtransactionstrategies.ForexampleforHibernate,thereisfirst-classsupportwithlotsofIoCconveniencefeatures,addressingmanytypicalHibernateintegrationissues.AllofthesesupportpackagesforO/RmapperscomplywithSpring'
sgenerictransactionandDAOexceptionhierarchies.Thereareusuallytwointegrationstyles:
eitherusingSpring'
sDAO'
templates'
orcodingDAOsagainstplainHibernate/JDO/TopLink/etcAPIs.Inbothcases,DAOscanbeconfiguredthroughDependencyInjectionandparticipateinSpring'
sresourceandtransactionmanagement.
saddssignificantsupportwhenusingtheO/Rmapp