如何在Filter
中获取url参数路线
GET /:lang/ controllers.SiteIndex.index(lang)
GET /:lang/genres/ controllers.Genres.allGenres(lang)
全局
object Global extends GlobalSettings {
override def onRouteRequest(request: RequestHeader): Option[Handler] = {
val a = request.getQueryString("lang")
val b = request.getQueryString("language")
println("executed before every request:" + request.toString)
super.onRouteRequest(request)
}
}
如何在Global中获取参数lang并在所有操作中设置语言
答案 0 :(得分:0)
我认为使用自定义操作构建器会更容易,因为onRouteRequest不会影响传递给您操作的参数。你可以得到类似的东西:
def myAction = ActionWithLang { req: MyCustomReqWithLang =>
...
Ok("woo " + req.myLang)
}
查看动作合成下的播放文档,了解有关此内容的更多信息:https://www.playframework.com/documentation/2.3.x/ScalaActionsComposition