无法形成网址和带有参数的操作

时间:2018-09-05 17:07:30

标签: playframework-2.6

我有一个Action,应该为多个URL调用。

 def index(signupMessage:Option[String]) = addToken {
        silhouette.UserAwareAction { implicit request =>
        println(s"index action called with request ${utilities.printPlayHttpRequest(request)}")
        println(s"index page's argument "+signupMessage)
        val Token(name, value) = CSRF.getToken.get
        println(s"Token name ${name}, value ${value}")
        Ok(views.html.index(/*signupMessage:Option[String]*/messagesApi("app.title")(langs.availables(0))))
      }
    }

以下网址应映射到同一操作

/ /home /home;signup="success" /home;signup="error"

我在routes.conf文件中创建了以下路由,但代码未编译。我在做什么错

GET     /                           controllers.HomeController.index(signup = None)

GET     /home/:signup        controllers.HomeController.index(signup:Option[String])

错误是

C:\Users\manuc\Documents\manu\codingjedi\code_related\code\frontend\web\conf\routes:12: No URL path binder found for type Option[String]. Try to implement an implicit PathBindable for this type.
    [error] GET     /home/:signup        controllers.HomeController.index(signup:Option[String])
    [error] C:\Users\manuc\Documents\manu\codingjedi\code_related\code\frontend\web\conf\routes:12: not enough arguments for method implicitly: (implicit e: play.api.mvc.PathBindable[Option[String]])play.api.mvc.PathBindable[Option[String]].
    [error] Unspecified value parameter e.
    [error] GET     /home/:signup        controllers.HomeController.index(signup:Option[String])
    [error] C:\Users\manuc\Documents\manu\codingjedi\code_related\code\frontend\web\conf\routes:12: No URL path binder found for type Option[String]. Try to implement an implicit PathBindable for this type.
    [error] GET     /home/:signup        controllers.HomeController.index(signup:Option[String])
    [error] C:\Users\manuc\Documents\manu\codingjedi\code_related\code\frontend\web\conf\routes:12: not enough arguments for method implicitly: (implicit e: play.api.mvc.PathBindable[Option[String]])play.api.mvc.PathBindable[Option[String]].
    [error] Unspecified value parameter e.
    [error] GET     /home/:signup        controllers.HomeController.index(signup:Option[String])
    [error] C:\Users\manuc\Documents\manu\codingjedi\code_related\code\frontend\web\conf\routes:7: method index is defined twice;
    [error]   the conflicting method index was defined at line 22:9
    [error] GET     /                           controllers.HomeController.index(signup = None)
    [error] C:\Users\manuc\Documents\manu\codingjedi\code_related\code\frontend\web\conf\routes:7: type mismatch;
    [error]  found   : String
    [error]  required: Option[String]
    [error] GET     /                           controllers.HomeController.index(signup = None)
    [error] C:\Users\manuc\Documents\manu\codingjedi\code_related\code\frontend\web\conf\routes:7: type mismatch;
    [error]  found   : None.type
    [error]  required: String
    [error] GET     /                           controllers.HomeController.index(signup = None)
    [error] C:\Users\manuc\Documents\manu\codingjedi\code_related\code\frontend\web\conf\routes:12: No URL path binder found for type Option[String]. Try to implement an implicit PathBindable for this type.
    [error] GET     /home/:signup        controllers.HomeController.index(signup:Option[String])
    [error] C:\Users\manuc\Documents\manu\codingjedi\code_related\code\frontend\web\conf\routes:12: not enough arguments for method fromPath: (implicit binder: play.api.mvc.PathBindable[Option[String]])play.core.routing.Param[Option[String]].
    [error] Unspecified value parameter binder.
    [error] GET     /home/:signup        controllers.HomeController.index(signup:Option[String])
    [error] 9 errors found
    [error] (compile:compileIncremental) Compilation failed
    [error] application - 

    ! @796k0gd0d - Internal server error, for (GET) [/] ->

    play.sbt.PlayExceptions$CompilationException: Compilation error[No URL path binder found for type Option[String]. Try to implement an implicit PathBindable for this type.]

0 个答案:

没有答案