Play Framework将val放入Action Builder Scala中

时间:2018-07-31 08:19:14

标签: playframework

我有自定义动作生成器,该生成器必须检查我的val值是否正确

class CheckAction @Inject()(parser: BodyParsers.Default)(implicit ec: ExecutionContext) extends ActionBuilderImpl(parser) {
    override def invokeBlock[A](request: Request[A], block: Request[A] => Future[Result]) = {
    if (Base16.decode( HERE I NEED MY VAL).isSuccess) block(request) else resolve(Results.Forbidden)
  }
}

我的路线是这样

GET        /api/block/:id      controllers.BlockController.findBlockApi(id: String)

控制器是

def findA(id: String): Action[AnyContent] = checkAction(id) {
....

那么如何将:id从路由放置到自定义操作生成器中?

1 个答案:

答案 0 :(得分:1)

查找答案。 1)ActionBuilder:

Test-Path -Path "\\$Computer\C$\Temp2"

2)控制器:

class Base16CheckAction(parser: BodyParsers.Default, modifierId: String) extends ActionBuilderImpl(parser) {
   override def invokeBlock[A](request: Request[A], block: Request[A] => Future[Result]): Future[Result] =
   if (Base16.decode(modifierId).isSuccess) block(request) else resolve(Results.BadRequest)
}

class Base16CheckActionFactory @Inject()(parser: BodyParsers.Default) {
  def apply(modifierId: String): Base16CheckAction = new Base16CheckAction(parser, modifierId)
}