gpt4 book ai didi

scala - Scala Play Framework中的方法重载错误

转载 作者:行者123 更新时间:2023-12-02 11:05:51 24 4
gpt4 key购买 nike

我正在编写一种在用户验证后正确设置 session cookie的方法。如下设置cookie无效。以下代码段导致“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)
}
}
)
}

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

最佳答案

我认为withSession需要一个String,String

看看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))

关于scala - Scala Play Framework中的方法重载错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12379774/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com