implicit request ?

不了解或不會Action在play framework很難再深入下去, 這是http request的點

以下這段代碼困擾我很久, 如今我才剛了解

Action { implicit request =>
Ok("Got request [" + request + "]")
}

原文這麼說

It is often useful to mark the request parameter as
implicit so it can be implicitly used by other APIs that need
it:

如果request成了隱式參數的話, 有個好處, 如果我寫了一個方法然後可以隱式的傳入play.api.mvc.Request 這個類型的參數

def f(implicit request: play.api.mvc.Request) = {
...
}

那我在調用 函式的時候就可以省略request參數了, 我想這只是種語法糖,
對代碼的結果不會有任何副作用.

时间: 2024-08-24 22:30:42

implicit request ?的相关文章

How to put an object on the request in a servlet

Many times when you're working with Java servlets and JSP's, you'll want to forward some piece of information from your servlet to your JSP without having to put that piece of information into thesession. For instance, in many applications you may no

MVC之前的那点事儿系列(5):HttpPipeline详细分析(下)(转载)

MVC之前的那点事儿系列(5):HttpPipeline详细分析(下) 文章内容 接上面的章节,我们这篇要讲解的是Pipeline是执行的各种事件,我们知道,在自定义的HttpModule的Init方法里,我们可以添加自己的事件,比如如下代码: public class Test : IHttpModule { public void Init(HttpApplication context) { context.BeginRequest += new EventHandler(context_

【Android】键盘的展开和收起

键盘的展开和收起主要使用到类InputMethodManager:http://developer.android.com/reference/android/view/inputmethod/InputMethodManager.html 其大致方法如下: 1 public void hide_keyboard_from(Context context, View view) { 2 InputMethodManager inputMethodManager = (InputMethodMan

Playframework2的Security使用

利用play.api.mvc.Security的机制,实现一个trait,用于扩展controller的用户认证机制. 该trait需要实现的方法包括: 1. def username(request: RequestHeader) = request.session.get("email") 2. def onUnauthorized(request: RequestHeader) = Results.Redirect(routes.Application.login) 3. def

Scala下Play框架学习笔记(Actions,Controllers and Results)

Scala下Play框架的学习是一件辛苦的事情,因为该框架比较新,scala语言也较新,所以中文资料很少,经过同事推荐,去了如下英文网站看资料: https://www.playframework.com/documentation/2.5.x/ScalaHome 虽然我的同事以在云中飞的速度学完了,但对我来说还是任重而道远. Action是什么? 由于Scala和Play有关的API都在play.api下面,所以其实Action的过程是这样的: play.api.mvc.Action(play

MVC之前的那点事儿系列(5):Http Pipeline详细分析(下)

文章内容 接上面的章节,我们这篇要讲解的是Pipeline是执行的各种事件,我们知道,在自定义的HttpModule的Init方法里,我们可以添加自己的事件,比如如下代码: public class Test : IHttpModule { public void Init(HttpApplication context) { context.BeginRequest += new EventHandler(context_BeginRequest); context.AuthenticateR

Scala下Play框架学习笔记(Session and Flash scopes)

session和flash scope 的区别 如果需要通过多个HTTP请求传输数据,那么就要用到session和flash scope.在session中存储的,整个会话过程都有效,在flash scope 中存储的,只是对下一个请求有效.服务器不存储session和flash scope中的数据,它们只是被传递给了下一个请求,使用Cookies机制.这就意味着你只能存储字符串类型,而且大小有限,最多4KB.Cookies的默认名字是PLAY_SESSION,通过application.con

Play2 Action梳理

研究它的原因是在用它提供的ActionBuilder,ActionFilter,ActionTransform的时候,感觉API提供的不够灵活. play将后台处理前台的请求的过程封装为Handler,我们先只看关于http部分的.也就是只看下Action. Action 下面是Action trait的一些信息 trait EssentialAction extends (RequestHeader => Iteratee[Array[Byte], Result]) with Handler

PLAY2.6-SCALA(十二) 表单的处理

一.表单处理流程如下 1.定义一个表单,在这里表单最多有22个字段 import play.api.data._ import play.api.data.Forms._ //要使用验证和约束 import play.api.data.validation.Constraints._ case class UserData(name: String, age: Int) val userForm = Form( mapping( "name" -> text, "age