mysql - 找不到参数 c : anorm. Column [Float] 的隐式值

标签 mysql sql scala playframework anorm

我遇到了类似的问题,但对我没有帮助。 (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/

相关文章:

mysql - Sqoop 导出到 Aurora RDS 的速度非常慢

mysql - 错误代码 : 1022. 无法写入;表中的重复键

mysql 检索字段名称作为记录集的一部分

javascript - 优化 SQL 连接?

sql - plpgsql 函数。如何将值与一组值进行比较?

sql - 如何使用spark sql过滤特定聚合的行?

php - 使用 Zend_Db_Adapter_PDO_Mysql 类连接到 mysql 数据库

scala - Scala 中高级类型的类型类实例中的两个参数函数,如何将这个简单的 Haskell 代码转换为 Scala?

scala - Spark 和 HBase 快照

java - 访问应用程序外部文件夹文件以在 Play Framework 2.6.x 模板中渲染的方式是什么?