- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我遇到了类似的问题,但对我没有帮助。 (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/
object Users { implicit object UserReads extends Reads[User] { def reads(json: JsValue) = JsS
解决方案:我不知道如何返回 Option[User] 的不存在,所以在没有找到用户的情况下,我创建了一个虚拟用户对象并从 Controller 对其进行推理(感觉很糟糕但有效。 ..):来自 Appl
在 Play 框架 2.0 中,我试图使用这样的行解析器从 PostgreSQL 加载一个真正的(即单精度浮点数)类型的列: case class Foo(bar: Float) object Foo
我想在 Scala 中将数据从 SQL server 复制到 vertica,我正在考虑使用 Anorm,但我没有找到任何关于批量插入的文档。如果 Anorm 不支持批量插入,我应该使用什么库? 最佳
我已经使用 Play framework 2.0 大约 6 个月了,我一直想知道为什么他们使用这么多样板代码来解析我的 SQL 查询返回,如下所示: case class Journal_accoun
当我尝试运行时(来自 Play Framework): import play.api.db.DB import anorm._ import org.joda.time.DateTime impor
在 yabe 示例中,有以下查询: def allWithAuthor:List[(Post,User)] = SQL( """
我刚刚开始使用 Anorm 和解析器组合器。似乎有很多样板代码。例如,我有 case class Model( id:Int, field1:String, field2:In
我正在使用游戏!框架与 Anorm 一起访问数据库。我经常看到像下面这样的例子,对象成员被直接注入(inject)到 SQL 语句中。 我的问题是,这些输入是否经过 sanitizer ?大多数示例如
考虑像这样的存储库/DAO 方法,效果很好: def countReports(customerId: Long, createdSince: ZonedDateTime) = DB.withCo
首先,我是 Play 2 Scala 的新手。我正在尝试将我的模型对象与 JSON 进行转换。 根据此博客 http://mandubian.com/2012/10/01/unveiling-play
我发现这个答案可以解决一个字段 -> Inserting multiple values into table with anorm var fields: List[String] = Nil
更新查询返回1,但插入查询返回None。 def que3(params) { DB.withConnection { implicit c => val i=SQL("UPDATE QUE
我正在尝试使用 Anorm(在 play framework 2.3.1 中)对 MySQL 数据库表进行批量插入。我正在构建的应用程序除了需要批量数据插入外,还有一个标准的 Web 前端,我想尝试将
当有记录匹配 WHERE 子句时,这段代码工作正常: val pinfo = SQL("SELECT * FROM tableName WHERE id={id}").on("id" -> "scal
我不想删除并重新插入每一行,所以我使用以下方法尝试将多行与异常一起使用: SQL(""" delete from PERSON_ROLES WHERE
是否可以在 Anorm 中使用带有字符串插值的 LIKE 子句? // e.g. this doesn't work SQL"SELECT * FROM users WHERE last_name L
我有一个可以为空列的表,当查询空列时,它抛出了错误 val row: List[(String,String)] = SQL("select top 10 Spare_Part part,Prici
使用 findBy 如下所示,我可以通过 key 和 value 在 Authentications 表中搜索记录 def findBy(key: String, value: String): An
你如何在 Scala 的游戏之外使用 Anorm?在用于 Play 的 Anorm 文档中,它只是使用以下内容: DB.withConnection { implicit c => val res
我是一名优秀的程序员,十分优秀!