如何在SIRD路由器中提取动态部分(简单路由器)

问题描述 投票:0回答:1

我创建了一个SIRD路由器

class UserRouter @Inject()(controller:UserController) extends SimpleRouter {

  override def routes:Routes = {
    case GET (p"/signup/:token") =>{  //corresponds to email verification from user after sign up. This was the URL which the server had sent
      println("add user request with token"); //TODOM - print token
      controller.verifyUser(); //
    }

  }
}

routes.conf中使用SIRD路由器的代码是

->      /ws/users                      WSRouters.UserRouter #use UserRouter for /ws/users

行动是

  def verifyUser(token:String) = Action.async{
    implicit request => {
      println("verifyUser action called with token: "+token) //TODOM - add proper handling and response
      Future(Ok("user verified"))
    }
  }

如何从token中的url(case GET (p"/signup/:token"))中提取动态部分并将其传递给verifyUser?在正常的routes.conf。我可以简单地做像GET /home/:id controllers.HomeController.index2(id)这样的事情,但是当我在SIRD路由器中做同样的事情时,我得到token未定义的错误

case GET (p"/signup/:token") =>{  //corresponds to email verification from user after sign up. This was the URL which the server had sent
      println("add user request with token"); //TODOM - print token
      controller.verifyUser(token); //COMPILE ERROR - token is undefined.
    }
playframework-2.6
1个回答
0
投票

正确的方法是使用$token而不是:token

case GET (p"/signup/$token") =>{  //corresponds to email verification from user after sign up. This was the URL which the server had sent
      println("add user request with token"+token); //TODOM - print token
      controller.verifyUser(token); //
    }
© www.soinside.com 2019 - 2024. All rights reserved.