中英文翻译--Spring的web MVC 构架模式(精品doc)Word文件下载.docx
- 文档编号:983155
- 上传时间:2023-04-29
- 格式:DOCX
- 页数:5
- 大小:14.10KB
中英文翻译--Spring的web MVC 构架模式(精品doc)Word文件下载.docx
《中英文翻译--Spring的web MVC 构架模式(精品doc)Word文件下载.docx》由会员分享,可在线阅读,更多相关《中英文翻译--Spring的web MVC 构架模式(精品doc)Word文件下载.docx(5页珍藏版)》请在冰点文库上搜索。
〃0hno,notyetanotherwebframework^.ThisarticlewilloutlinewhySpringisn,tparticularlyawebframeworkbutagenericlightweightapplicationframeworkwithdedicatedwebsupport,andshowthearchitecturaldifferencestoStrutsandWebWorkIncontrasttoStrutsorWebWork,Springisanapplicationframeworkforalllayers:
Itoffersabeanconfigurationfoundation,AOPsupport,aJDBCabstractionframework,abstracttransactionsupport,etc.Itisaverynon-intrusiveeffort:
YourapplicationclassesdonotneedtodependonanySpringclassesifnotnecessary,andyoucanreuseeverypartonitsownifyouliketo.Fromitsverydesign,theframeworkencouragescleanseparationoftiers,mostimportantlywebtierandbusinesslogic:
e.g.thevalidationframeworkdoesnotdependonwebcontrollers.Majorgoalsarereusabilityandtestability:
Unnecessarycontainerorframeworkdependenciescanbeconsideredavoidableevils.
Ofcourse,Spring,sownwebsupportisnicelyintegratedwiththeframework,sgeneralpatterns.Nevertheless,replacingthewebsolutionwithStruts,WebWork,orthelikeiseasy.BothwithSpring'
swebsupportoradifferentone,Springallowsforbuildingatruededicatedmiddletierinthewebcontainer,withtheoptiontoreuseexactlythesamebusinesslogicintestenvironmentsorstandaloneapplications.AndwithinJ2EE,yourbusinesslogicwillnotunnecessarilydependoncontainerserviceslikeJTAorEJB-allowingcomplex,we11-architectedwebapplicationstorunina"
simple"
containerlikeTomcatorResin.
NotethatSpringdoesn,tgenerallyaimtocompetewithexistingsolutions.ItratherfostersseamlessintegrationwithstandardslikeServlet,JSP,JTA,JNDI,JDBC,andJDO,andwell-suitedtoolslikeHibernate,Velocity,Log4J,andCaucho,sHessian/Burlap.Theframeworkisdesignedtogrowwiththeneedsofyourapplications,intermsoftechnologychoice:
Forexample,youwillprobablyuseJTAviaSpring,sJtaTransactionManagerifyouneeddistributedtransactions-butonlythen,asthereareperfectreplacementsforsingledatabases,likeDataSourceTransactionManagerorHibernateTransactionManager.
2. WebMVC:
TheDesignofSpring'
sWebFramework
Spring,swebframeworkisdesignedaroundaDispatcherServletthatdispatchesrequeststohandlers,withconfigurablehandlermappings,viewresolution,andlocaleandthemeresolution.ThedefaulthandlerisaverysimpleControllerinterface,justofferinga/zModelAndViewhandleRequest(request,response)〃method.Thiscanalreadybeusedforapplicationcontrollers,butyouwillprefertheincludedimplementationhierarchy,consistingofAbstractcontroller,AbstractCommandControIler,MultiActionController,SimpleFormController,AbstractWizardFormControIler.Applicationcontrollerswilltypicallybesubclassesofthose.Notethatyoucanchooseanappropriatebaseclass:
Ifyoudon,thaveaform,youdon,tneedaFormController.ThisisamajordifferencetoStruts.
Youcantakeanyobjectascommandorformobject:
There,snoneedtoimplementaninterfaceorderivefromabaseclass.Spring,sdatabindingishighlyflexible,e.g.ittreatstypemismatchesasvalidationerrorsthatcanbeevaluatedbytheapplication,notassystemerrors.Soyoudon,tneedtoduplicateyourbusinessobjects'
propertiesasStringsinyourformobjects,justtobeabletohandleinvalidsubmissions,ortoconverttheStringsproperly.Instead,it'
softenpreferabletobinddirectlytoyourbusinessobjects.ThisisanothermajordifferencetoStrutswhichisbuiltaroundrequiredbaseclasseslikeActionandActionForm-foreverytypeofaction.ComparedtoWebWork,Springhasmoredifferentiatedobjectroles:
ItsupportsthenotionofaController,anoptionalcommandorformobject,andamodelthatgetspassedtotheview.Themodelwillnormallyincludethecommandorformobjectbutalsoarbitraryreferencedata.Instead,aWebWorkActioncombinesallthoserolesintoonesingleobject.WebWorkdoesallowyoutouseexistingbusinessobjectsaspartofyourform,butjustbymakingthembeanpropertiesoftherespectiveActionclass.Finally,thesameActioninstancethathandlestherequestgetsusedforevaluationandformpopulationintheview.Thus,referencedataneedstobemodelledasbeanpropertiesoftheActiontoo.Thesearearguablytoomanyrolesinoneobject.
Regardingviews:
Spring'
sviewresolutionisextremelyflexible.AControllerimplementationcanevenwriteaviewdirectlytotheresponse,returningnullasModelAndView.Inthenormalcase,aModelAndViewinstanceconsistsofaviewnameandamodelMap,containingbeannamesandcorrespondingobjects(likeacommandorform,referencedata,etc).Viewnameresolutionishighlyconfigurable,eitherviabeannames,viaapropertiesfile,orviayourownViewResolverimplementation.TheabstractmodelMapallowsforcompleteabstractionoftheviewtechnology,withoutanyhassle:
BeitJSP,Velocity,oranythingelse-everyTenderercanbeintegrateddirectly.ThemodelMapsimplygetstransformedintoanappropriateformat,likeJSPrequestattributesoraVelocitytemplatemodel.
3. Integration:
UsingaDifferentWebFrameworkwithSpring
Manyteamswilltrytoleveragetheirinvestmentsintermsofknow-howandtools,bothforexistingprojectsandfornewones.Concretely,therearenotonlyalargenumberofbooksandtoolsforStrutsbutalsoalotofdevelopersthathaveexperiencewithit.Thus,ifyoucanlivewithStruts,architecturalflaws,itcanstillbeaviablechoicefortheweblayer.ThesameappliestoWebWorkandotherwebframeworks.
Ifyoudon,twanttouseSpring,swebMVCbutintendtoleverageothersolutionsthatSpringoffers,youcanintegratethewebframeworkofyourchoicewithSpringeasily.SimplystartupaSpringrootapplicationcontextviaitsContextLoaderListener,andaccessitviaitsServletContextattribute(orSpring,srespectivehelpermethod)fromwithinaStrutsorWebWorkaction.Notethattherearen,tany〃plugins〃involved,thereforenodedicatedintegration:
Fromtheviewoftheweblayer,you,11simplyuseSpringasalibrary,withtherootapplicationcontextinstanceasentrypoint.AllyourregisteredbeansandallofSpring,sservicescanbeatyourfingertipsevenwithoutSpring'
swebMVC.Springdoesn,tcompetewithStrutsorWebWorkinthisusage,itjustaddressesthemanyareasthatthepurewebframeworksdon,t,frombeanconfigurationtodataaccessandtransactionhandling.SoyouareabletoenrichyourapplicationwithaSpringmiddletierand/ordataaccesstier,evenifyoujustwanttousee.g.thetransactionabstractionwithJDBCorHibernate.
4. FeatureCheckList
Ifjustfocussingonthewebsupport,someofSpring,suniquefeaturesare:
.Clearseparationofroles:
controllervsvalidatorvscommandobjectvsformobjectvsmodelobject,DispatcherServletvshandlermappingvsviewresolver,etc.・PowerfulandstraightforwardconfigurationofbothframeworkandapplicationclassesasJavaBeans,includingeasyin-betweenreferencingviaanapplicationcontext,e.g.fromwebcontrollerstobusinessobjectsandvalidators..Adaptability,non-intrusiveness:
UsewhateverControllersubclassyouneed(plain,command,form,wizard,multiaction,oracustomone)foragivenscenarioinsteadofderivingfromAction/ActionFormforeverything..Reusablebusinesscode,noneedforduplication:
YoucanuseexistingbusinessobjectsascommandorformobjectsinsteadofmirroringtheminspecialActionFormsubclasses..Customizablebindingandvalidation:
typemismatchesasapplication-levelvalidationerrorsthatkeeptheoffendingvalue,localizeddateandnumberbinding,etcinsteadofString-onlyformobjectswithmanualparsingandconversiontobusinessobjects.Customizablehandlermapping,customizableviewresolution:
flexiblemodeltransfervianame/valueMap,handlermappingandviewresolutionstrategiesfromsimpletosophisticatedinsteadofonesingleway.Customizablelocaleandthemeresolution,supportforJSPswithandwithoutSpringtaglibrary,supportforJSTL,supportforVelocitywithouttheneedforextrabridges,etc.SimplebutpowerfultaglibrarythatavoidsHTMLgenerationatanycost,allowingformaximumflexibilityintermsofmarkupcode.
翻译文稿
Spring的webMVC构架模式
1. 介绍:
Spring应用构架
当你第一次看到Spring的时候,你一定会说:
〃哦不,又一种web构架〃.这篇文章将告诉你Spring明显区别于其他轻量级applicationframework,它将专注于web的支持,与struts和webwork有着明显的区别。
在和struts和webwork的对比上,Spring是一个服务于所有层面的applicationframework:
提供了bean的配置基础,A0P的支持,JDBC的提取框架,抽象事务支持,等等。
它有一个非常显著的特点:
在某个层面上如果你不需要Spring的支持,你就可以不使用String的class,只使用它的某一部分的功能。
从它的设计理念,你可以看到String帮助你实现了真正的逻辑层和web层的分离:
例如。
一个校验应用将不用依靠controllers,就可以实现。
这样的目标是更好的重用和易测:
过分依靠不必要的容器和框架将不能实现这一点。
当然,Spring的自己的web支持和通常框架模式的细致完整.然而,Spring替换struts,webwork或者其他的web方案非常的容易.对于Spring的web支持或者不同的地方,Spring允许你在web容器里面建立一个中间层,在测试环境或者标准独立的应用里面来设置重用你的商务逻辑.还有在J2EE环境里面,你的商务逻辑不必依靠容器提供的服务,像JTA,EJB的支持.良好的构架的web应用可以运行在任何容器上,如,Tomcat或者Resin.值得注意的是,Spring不是和已经存在的解决方案进行竞争.我们鼓励结合标准的技术,如,Servlet,JSP,JTA,JNDI,JDBC,andJDO,和非常匹配的工具,如,Hibernate,Velocity,Log4J,andCaucho'
sHessian/Burlap,这个框架的的设计思想是在你的应用需要改良的时候,你将会做一些技术的选择:
例如,如果你需要分布式事务处理,你可能需要用Spring的JtaTransactionManager来实现JTA服务.或者,用DataSourceTransactionManagerorHibernateTransactionManager来实现美妙完美的单个数据库交换。
Springweb框架的设计思想
Spring框架通过配置操作mappings,展示resolution,本地化和模版集成围绕着分派请求操作的servlet-DispatcherServlet设计的.缺省的操作是一个非常简单的控制接口,他只提供了ModelAndViewhandleRequest(request,response)方法.这将用于一个应用的控制,但是,如果你想包含多个层次的控制,Abstractcontroller,AbstractCommandController,MultiActionController,SimpleFormContro
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 中英文翻译-Spring的web MVC 构架模式精品doc 中英文 翻译 Spring web 构架 模式 精品 doc