作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是 Application.scala 中 zentask 示例中的一个函数。
我试图理解它...
f: => 字符串是什么意思?
f: => String => Request[AnyContent] => Result 的链接怎么样
/**
* Action for authenticated users.
*/
def IsAuthenticated(f: => String => Request[AnyContent] => Result) =
Security.Authenticated(username, onUnauthorized) { user =>
Action(request => f(user)(request))
}
最佳答案
形式为 fn: => String
的参数表示返回(或为)字符串的“生成器”(函数或值),因此,例如,您可能有一个方法定义为
def myMethod(fn: => String): String = "Fn output = " + fn
def myFn: String = "Hello!"
// Alternatively: def myFn(): String = "Hello!"
// or: val myFn: () => String = "Hello!"
// or most simply: val myString = "Hello!"
val output = myMethod(myFn) // output = "Fn output = Hello!"
def my2ndMethod(fn: String => Int): Int = fn("4")
def my2ndFn(input: String) = 5 * input.toInt
// Alternatively: val my2ndFn: String => Int = input => 5 * input.toInt
val output2 = my2ndMethod(my2ndFn _) // output2 = 20
Request[AnyContent]
并且(最后)返回一个结果(呸!)。
def authFn(username: String)(request: Request[AnyContent]): Result
val authenticatedResult = IsAuthenticated(authFn _)
关于scala - 从 Play 框架 zentask 示例中了解 Scala 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17960092/
Solution: you dont need IDE for testing, just run "play test" in the console 晚上好!我刚开始接触 Play Framewo
这是 Application.scala 中 zentask 示例中的一个函数。 我试图理解它... f: => 字符串是什么意思? f: => String => Request[AnyConten
我玩 Play 2.0,Scala 版本。目前,我分析 Zentasks sample app . 此应用程序的一部分是身份验证机制,主要包含在 Secured 特性中。我想知道如何测试安全操作,例如
有两个相关的问题: 看起来在旧的“正常”压缩 Play 发行版中有包含样本的文件夹。但是我在哪里可以找到安装了激活器的 play 的 2.3.x 的它们? 除了开源中的示例应用程序之外,还有其他东西吗
我是一名优秀的程序员,十分优秀!