我遇到了类似的问题,但对我没有帮助。 (Anorm parse float values)。
老实说,我不明白那个问题的答案。
我收到此编译时间错误:
could not find implicit value for parameter c: anorm.Column[Float]
在
def getInformation(id: Long): List[(Float, Float, Float)] = {
DB.withConnection { implicit con =>
val query = SQL("select principal,interest,value from myTable where userId={id} and status=true").on("id"->id)
val result = query().map { row =>
Tuple3(row[Float]("principal"), row[Float]("inetrest"), row[Float]("value"))
// ^
}.toList
return result
}
}
最佳答案
也许对 implicit 的简短回顾对您有所帮助。让我们构建一个非常基本的示例:
// some class which will be used as implicit (can be anything)
case class SomeImplicitInformation(maybe: Int, with: Int, data: Int)
// lets assume we have a function that requires an implicit
def functionRequiringImplicit(regularParameters: Int)(implicit imp: SomeImplicitInformation) {
// ...
}
// now if you try to call the function without having an implicit in scope
// you would have to pass it explicitly as second parameter list:
functionRequiringImplicit(0)(SomeImplicitInformation(0,0,0))
// instead you can declare an implicit somewhere in your scope:
implicit val imp = SomeImplicitInformation(0,0,0)
// and now you can call:
functionRequiringImplicit(0)
你得到的错误只是说 anorm.Column[Float]
不在隐含的范围内。您可以通过将其隐式添加到您的范围或显式传递来解决它。
为您提供更详细的说明:由于 Column
伴生对象只为 rowToDouble
提供隐含的,您只需使用 the code that is linked in your question .为了让它工作,把它放在你的结果计算之前。稍后您可能希望将它放在某个封闭范围内的 val
中。
关于mysql - 找不到参数 c : anorm. Column [Float] 的隐式值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23340849/