【问题标题】:Overloaded method error in Scala Play FrameworkScala Play 框架中的重载方法错误
【发布时间】:2012-09-12 13:27:22
【问题描述】:

我正在编写一种在用户进行身份验证后正确设置会话 cookie 的方法。如下设置 cookie 不起作用。以下 sn-p 导致“withSession”调用出错:

重载的方法值 [withSession] 不能应用于 ((String, Long))

代码:

/**
 * Process login form submission.
 */
def authenticate = Action { implicit request =>
  loginForm.bindFromRequest.fold(
    formWithErrors => BadRequest(views.html.login(formWithErrors)),
    credentials => {
      val user = models.User.findByEmail(credentials._1)

      user match {
        case Some(u) => {
          Redirect(routes.Dashboard.index).withSession(Security.username -> u.id)
        }
        case None => Redirect(routes.Auth.login)
      }
    }
  )
}

'credentials' 只是一个包含用户提交的电子邮件和密码的元组。如果我摆脱了“withSession”部分,那么它运行良好。如果我将“重定向”语句从模式匹配代码中移出,则可以正常工作。为什么它不能像我上面那样工作,我该如何解决?

【问题讨论】:

    标签: scala playframework compiler-errors playframework-2.0


    【解决方案1】:

    我认为 withSession 需要一个字符串,字符串

    看看http://www.playframework.org/documentation/api/2.0.3/scala/index.html#play.api.mvc.SimpleResult

    def withSession(session: (String, String)*): PlainResult = withSession(Session(session.toMap))
    

    【讨论】:

      猜你喜欢
      • 2018-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-15
      • 2013-05-27
      • 2015-01-20
      • 2019-04-11
      相关资源
      最近更新 更多