Scala,Play Framework Slick问题 - 无法找到参数rconv的隐含值

时间:2013-10-27 20:51:46

标签: scala playframework playframework-2.0 slick play-slick

我正在遵循Slick documentation的指导方针,我不明白我在这里做错了什么:

package models

import scala.slick.session.Database
import Database.threadLocalSession
import scala.slick.jdbc.{GetResult, StaticQuery => Q}
import javax.sql.DataSource
import Q.interpolation

object Data {

    case class User(user: String, password: String)

    lazy val db = Database.forName("default")

    def result: Option[User] = {
        db.withSession {
            sql"SELECT user, password FROM user WHERE user = 'user' AND password = 'pass'".as[User]
        }
    }

}

该行

sql"SELECT user, password FROM user WHERE user = 'user' AND password = 'pass'".as[User]

给了我这个:

Multiple markers at this line
    - could not find implicit value for parameter rconv: scala.slick.jdbc.GetResult[models.Data.User]
    - could not find implicit value for parameter rconv: scala.slick.jdbc.GetResult[models.Data.User]

我在这里做错了什么?

Play Framework 2.2.0,Scala 2.10.3,Slick 1.0.1

1 个答案:

答案 0 :(得分:13)

您需要提供从结果到用户的转换功能。直接从slick home

复制和改编
implicit val getUserResult = GetResult(r => User(r.<<, r.<<))

或来自您关联的文档中的this section