如何从 play 2.6 scala 中的请求中获取 ROUTE_PATTERN
How to get ROUTE_PATTERN from request in play 2.6 scala
我在 play 2.5 中提取了 ROUTE_PATTERN:
request.tags.get("ROUTE_PATTERN")
现在我更新了 play 2.6,这段代码不再有效了。我在这里阅读了播放文档:
What’s new in Play 2.6
我试过了:
object Attrs {
val RoutePattern: TypedKey[String] = TypedKey("ROUTE_PATTERN")
}
request.attrs.get(Attrs.RoutePattern)
总是returnsNone。我如何在 play 2.6 中获取请求的 RoutePattern?
If you used any of the Router.Tags.*
tags, you should change your code to use the new Router.Attrs.HandlerDef
(Scala)....
This new attribute contains a HandlerDef
object with all the information that is currently in the tags. The current tags all correspond to a field in the HandlerDef
object....
HandlerDef
中对应旧 ROUTE_PATTERN
标签的字段是 path
:
import play.api.routing.{ HandlerDef, Router }
import play.api.mvc.RequestHeader
val handler = request.attrs(Router.Attrs.HandlerDef)
val routePattern = handler.path
我在 play 2.5 中提取了 ROUTE_PATTERN:
request.tags.get("ROUTE_PATTERN")
现在我更新了 play 2.6,这段代码不再有效了。我在这里阅读了播放文档: What’s new in Play 2.6
我试过了:
object Attrs {
val RoutePattern: TypedKey[String] = TypedKey("ROUTE_PATTERN")
}
request.attrs.get(Attrs.RoutePattern)
总是returnsNone。我如何在 play 2.6 中获取请求的 RoutePattern?
If you used any of the
Router.Tags.*
tags, you should change your code to use the newRouter.Attrs.HandlerDef
(Scala)....This new attribute contains a
HandlerDef
object with all the information that is currently in the tags. The current tags all correspond to a field in theHandlerDef
object....
HandlerDef
中对应旧 ROUTE_PATTERN
标签的字段是 path
:
import play.api.routing.{ HandlerDef, Router }
import play.api.mvc.RequestHeader
val handler = request.attrs(Router.Attrs.HandlerDef)
val routePattern = handler.path