中英文翻译--Spring的web MVC 构架模式(精品doc)Word格式文档下载.docx

上传人:b****1 文档编号:13107148 上传时间:2022-10-05 格式:DOCX 页数:5 大小:14.10KB
下载 相关 举报
中英文翻译--Spring的web MVC 构架模式(精品doc)Word格式文档下载.docx_第1页
第1页 / 共5页
中英文翻译--Spring的web MVC 构架模式(精品doc)Word格式文档下载.docx_第2页
第2页 / 共5页
中英文翻译--Spring的web MVC 构架模式(精品doc)Word格式文档下载.docx_第3页
第3页 / 共5页
中英文翻译--Spring的web MVC 构架模式(精品doc)Word格式文档下载.docx_第4页
第4页 / 共5页
中英文翻译--Spring的web MVC 构架模式(精品doc)Word格式文档下载.docx_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

中英文翻译--Spring的web MVC 构架模式(精品doc)Word格式文档下载.docx

《中英文翻译--Spring的web MVC 构架模式(精品doc)Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《中英文翻译--Spring的web MVC 构架模式(精品doc)Word格式文档下载.docx(5页珍藏版)》请在冰豆网上搜索。

中英文翻译--Spring的web MVC 构架模式(精品doc)Word格式文档下载.docx

JuergenHoeller

1. Introduction:

SpringtheApplicationFramework

WhenfirstconfrontedwiththeSpringFramework,onemightbetemptedtothink:

〃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).Viewnam

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

当前位置:首页 > 自然科学 > 物理

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1