欢迎来到天天文库
浏览记录
ID:47235597
大小:173.88 KB
页数:10页
时间:2019-07-25
《基于MVC模式的电子商务网站(B2C)的分析与设计》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、BasedonMVCPatternAnalysisanddesignofe-commerce(B2C)sitesBeforewestartourjourneyintotheinternalsofSpringMVC,wefirstneedtounderstandthedifferentlayersofawebapplication.Andwe’llbeginthatdiscussionwithabriefintroductionoftheMVCpatterningeneral,includingwhatitisandwhyshouldweuseit.AfterreviewingtheM
2、VCPattern,wewillgothroughthedifferentlayersinawebapplicationandseewhatroleeachlayerplaysintheapplication.TheModelViewControllerpattern(MVCpattern)wasfirstdescribedbyTrygveReenskaugwhenhewasworkingonSmalltalkatXerox.Atthattime,thepatternwasaimedatdesktopapplications.Thispatterndividesthepresenta
3、tionlayerintodifferentkindsofcomponents.Eachcomponenthasitsownresponsibilities.Theviewusesthemodeltorenderitself.Basedonauseraction,theviewtriggersthecontroller,whichinturnupdatesthemodel.Themodelthennotifiestheviewto(re)renderitself.TheMVCpatternisallaboutseparationofconcerns.Aswementionedprev
4、iously,eachcomponenthasitsownrole(seeTable3-1).Separationofconcernsisimportantinthepresentationlayerbecauseithelpsuskeepthedifferentcomponentsclean.Thisway,wedon’tburdentheactualviewwithbusinesslogic,navigationlogic,andmodeldata.Followingthisapproachkeepseverythingnicelyseparated,whichmakesitea
5、siertomaintainandtestourapplication.WhatIsMVC:MVCisadesignpatternthatbreaksanapplicationintothreeparts:thedata(Model),thepresentationlayer(View),andtheuserinteractionlayer(Controller).Inotherwords,theeventflowgoeslikethis:1.Theuserinteractswiththeapplication.2.Thecontroller’seventhandlerstrigge
6、r.3.Thecontrollerrequestsdatafromthemodel,givingittotheview.4.Theviewpresentsthedatatotheuser.Or,togivearealexample,Figure1-1showshowsendinganewchatmessagewouldworkwithHolla.Figure1-1.SendinganewchatmessagefromHolla1.Theusersubmitsanewchatmessage.2.Thecontroller’seventhandlerstrigger.3.Thecontr
7、ollercreatesanewChatModelrecord.4.Thecontrollerthenupdatestheview.5.Theuserseeshisnewchatmessageinchatlog.TheMVCarchitecturalpatterncanevenbeimplementedwithoutlibrariesorframeworks.ThekeyistodivideuptheresponsibilitiesoftheMVCcomp
此文档下载收益归作者所有