资源描述:
《基于mvc模式的电子商务网站b2c的分析与设计》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、-BasedonMVCPatternAnalysisanddesignofe-commerce(B2C)sitesBeforewestartourjourneyintotheinternalsofSpringMVC,wefirstneedtounderstandthedifferentlayersofawebapplication.Andwe’llbeginthatdiscussionwithabriefintroductionoftheMVCpatterningeneral,includingwhatitisandwhyshouldweuseit.Af
2、terreviewingtheMVCPattern,wewillgothroughthedifferentlayersinawebapplicationandseewhatroleeachlayerplaysintheapplication.TheModelViewControllerpattern(MVCpattern)wasfirstdescribedbyTrygveReenskaugwhenhewasworkingonSmalltalkatXerox.Atthattime,thepatternwasaimedatdesktopapplication
3、s.Thispatterndividesthepresentationlayerintodifferentkindsofcomponents.Eachcomponenthasitsownresponsibilities.Theviewusesthemodeltorenderitself.Basedonauseraction,theviewtriggersthecontroller,whichinturnupdatesthemodel.Themodelthennotifiestheviewto(re)renderitself.TheMVCpatternis
4、allaboutseparationofconcerns.Aswementionedpreviously,eachcomponenthasitsownrole(seeTable3-1).Separationofconcernsisimportantinthepresentationlayerbecauseithelpsuskeepthedifferentcomponentsclean.Thisway,wedon’tburdentheactualviewwithbusinesslogic,navigationlogic,andmodeldata.Follo
5、wingthisapproachkeepseverythingnicelyseparated,whichmakesiteasiertomaintainandtestourapplication.WhatIsMVC:MVCisadesignpatternthatbreaksanapplicationintothreeparts:thedata-页脚---(Model),thepresentationlayer(View),andtheuserinteractionlayer(Controller).Inotherwords,theeventflowgoes
6、likethis:1.Theuserinteractswiththeapplication.2.Thecontroller’seventhandlerstrigger.3.Thecontrollerrequestsdatafromthemodel,givingittotheview.4.Theviewpresentsthedatatotheuser.Or,togivearealexample,Figure1-1showshowsendinganewchatmessagewouldworkwithHolla.Figure1-1.Sendinganewcha
7、tmessagefromHolla1.Theusersubmitsanewchatmessage.2.Thecontroller’seventhandlerstrigger.3.ThecontrollercreatesanewChatModelrecord.4.Thecontrollerthenupdatestheview.5.Theuserseeshisnewchatmessageinchatlog.TheMVCarchitecturalpatterncanevenbeimplementedwithoutlibrariesorframeworks.Th
8、ekeyistodivideuptheresponsibilitiesofthe