我對着下面的問題中發揮2.5,而編譯。
您在範圍中沒有隱式應用程序。如果您想 將當前運行的應用程序帶入上下文中,請使用 依賴注入。
獲取問題在線 - DB.withConnection {^
代碼片段:
object User {
def getId(emailid: String): Option[Int] = {
DB.withConnection { implicit c =>
SQL("select id from user where email = {email}").on(
'email -> emailid).as(SqlParser.scalar[Int].singleOpt)
}
}
}
如何解決這個問題?
雖然現在解決了這個問題,但它將導致2.5中的棄用警告。一旦你升級到2.6,你將被迫使用依賴注入。 – rethab
有人可以解釋如何使用依賴注入完成這項工作嗎? – schub