我在播放控制器的许多方法中看到重复代码如下。既然请求在Actions中可用,那么可以用任何方法从所有方法中抽象出来以避免重复吗?
def serveData = Action { implicit request =>
val host = "http://" + request.host
答案 0 :(得分:1)
您可以这样做:
def withHost(f: String => SimpleResult) = Action { implicit request =>
val host = "http://" + request.host
f(host)
}
def serveData = withHost { host =>
Ok(host)
}