课程表

Revel课程

工具箱
速查手册

Revel 控制器概要

当前位置:免费教程 » 程序设计 » Revel

自定义Controller 是一个直接或间接嵌入了 *revel.Controller 的struct。

典型用法:

  1. type AppController struct {
  2. *revel.Controller
  3. }

*revel.Controller 在你自定义的struct中必须是第一个嵌入的类型

revel.Controller 用于请求的上下文,包含了请求与响应数据,请到 the godoc 查看完整内容, 下面是一个定义 (以及辅助类型的定义):

  1. type Controller struct {
  2. Name string // 控制器名称, 比如: "Application"
  3. Type *ControllerType // 控制器类型描述
  4. MethodType *MethodType // 控制器方法描述
  5. AppController interface{} // 控制器实例
  6.  
  7. Request *Request
  8. Response *Response
  9. Result Result
  10.  
  11. Flash Flash // 用户 cookie, 在请求之后清空
  12. Session Session // Session, 保存在cookie中,签名。
  13. Params *Params // URL和表单中的参数(包扩 multipart).
  14. Args map[string]interface{} // 每个请求的暂存空间
  15. RenderArgs map[string]interface{} // 传递给模板的参数
  16. Validation *Validation // 数据验证帮助器
  17. }
  18.  
  19. // 统一的请求参数包装
  20. // 包括:
  21. // - URL 查询字符串
  22. // - Form 表单字段
  23. // - File 文件上传
  24. type Params struct {
  25. url.Values
  26. Files map[string][]*multipart.FileHeader
  27. }
  28.  
  29. type Request struct {
  30. *http.Request
  31. ContentType string
  32. }
  33.  
  34. type Response struct {
  35. Status int
  36. ContentType string
  37. Headers http.Header
  38. Cookies []*http.Cookie
  39.  
  40. Out http.ResponseWriter
  41. }

作为HTTP请求处理的一部分,Revel实例化一个控制器,设置所有revel.Controller嵌入的属性, 因此, Revel 不在请求之间共享实例,对于每个请求的处理,控制器都是独立的。

转载本站内容时,请务必注明来自W3xue,违者必究。
 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号