不了解或不會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) = {
...
}
那我在調用 f 函式的時候就可以省略request參數了, 我想這只是種語法糖,
對代碼的結果不會有任何副作用.
时间: 2025-01-08 07:02:10