欢迎来到天天文库
浏览记录
ID:17938361
大小:28.99 KB
页数:21页
时间:2018-09-11
《play framework 框架 控制器(controller)》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、PlayFramework框架的控制器(Controller)Businesslogicismanagedinthedomainmodellayer.Asaclient(typicallyawebbrowser)cannotdirectlyinvokethiscode,thefunctionalityofadomainobjectisexposedasresourcesrepresentedbyURIs.业务逻辑是在域模型层里进行管理,客户端(典型的客户端就是浏览器)无法直接调用业务逻辑代码,客户端是通过资源的URI来访问到域对象。Aclientusestheunifor
2、mAPIprovidedbytheHTTPprotocoltomanipulatetheseresources,andbyimplicationtheunderlyingbusinesslogic.However,thismappingofresourcestodomainobjectsisnotabijection:thegranularitycanbeexpressedatdifferentlevels,someresourcesmaybevirtuals,forsomeresourcesaliasesmaybedefined…客户端使用HTTP协议中提供的统一方法来
3、访问这些特定资源,并隐式调用底层的业务逻辑。但是这种URI资源到域对象之间的映射关系并不是双向的,其粒度可以使用不同的层次来表示。某些资源可以是虚拟的,也可以给资源定义一个别名…ThisispreciselytheroleplayedbytheControllerlayer:providingagluebetweenthedomainmodelobjectsandtransportlayerevents.AstheModellayer,controllersarewritteninpureJava,makingiteasytoaccessormodifyModelobje
4、cts.LiketheHTTPinterface,ControllersareproceduralandRequest/Responseoriented.这正是控制器层所起的作用:提供一个域模型对象与传输层之间的映射关系。由于域模型层和控制器都是纯Java编写的,因此很容易访问或修改模型对象。与HTTP接口类似,控制器是面向过程和请求/响应模型的。TheControllerlayerreducestheimpedancemismatchbetweenHTTPandtheDomainModel.控制器层可减少由于HTTP协议和域模型之间不匹配的障碍。Note注意Therea
5、redifferentarchitecturalmodelswithdifferentstrategies.Someprotocolsgiveyoudirectaccesstothedomainmodelobjects.ThisistypicallywhatEJBorCorbaprotocolsdo.Inthesecases,thearchitecturalstyleusedisRPC(RemoteProcedureCall).Thesecommunicationstylesarehardlycompatiblewithwebarchitecture.不同的体系架构有着不
6、同的设计策略,某些协议可以让你直接访问域模型对象,例如EJB和CORBA协议就是这么做的。在这种情况下,使用的RPC远程过程调用的设计风格,这种设计风格很难跟Web应用兼容。SometechnologieslikeSOAPtrytogiveaccesstothemodelobjectdomainthroughtheWeb.However,SOAPisjustanotherRPC-styleprotocol,inthiscaseusingHTTPasatransportprotocol.Itisnotanapplicationprotocol.而另外一些技术例如SOAP试图
7、通过Web来访问域对象模型,但不管怎样,SOAP还是RPC风格的设计,尽管使用的是HTTP传输协议,这并不是应用的协议。Theweb’sprinciplesarenotfundamentallyobject-oriented.SoalayerisneededtoadaptHTTPtoyourfavoritelanguage.从根本上来说,Web的原则并不是面向对象的,因此需要引入一个用来将HTTP协议转化为你喜好的编程语言的层,这就是控制层。Acontrolleroverview控制器概述AControllerisaJavac
此文档下载收益归作者所有