【问题标题】:could not find implicit value for parameter c: anorm.Column[Float] Play Framework Scala找不到参数 c 的隐式值:anorm.Column[Float] Play Framework Scala
【发布时间】:2019-01-08 07:22:55
【问题描述】:

我无法在 play 框架中解析浮点值,它给了我一个编译错误。 所以从数据库中我得到的值是浮点数,但它不能确定值 作为浮动并给出浮动异常的错误。

它给出的错误是这样的

error

我的代码是这样的:

package model
import anorm._
import play.api.db._
import play.api.Play.current

case class Contact(id: String, VehiclePositionLattitude: Double, 
  VehiclePositionLongitude: Any)

object Contact {

  def all={

    DB.withConnection { implicit connection=>

      SQL("Select VehicleJourneyUID,VehiclePositionLattitude,VehiclePositionLongitude 
        from csv_output where  VehicleJourneyUID in (31356)")().map{ row=>
        Contact(
          id=row[String]("VehicleJourneyUID"),
          VehiclePositionLattitude=row[Double]("VehiclePositionLattitude"),
          VehiclePositionLongitude=row[Float]("VehiclePositionLongitude")
        )
      }.toList

    } 
  }
}

【问题讨论】:

  • 您也可以采用将其读取为浮点数并进行转换的方法(如果这样做安全的话?)您使用的是什么版本的游戏,因为它在我这边编译正常。我还看到您已将经度定义为 Any - 那肯定是 Float(或 Double)?

标签: scala anorm


【解决方案1】:

您是否尝试对浮点数使用隐式读写?或者如何使用 BigDecimal 数据类型验证它,即使它在 SQL 数据库中显示为 Float。

希望对你有帮助。

【讨论】:

  • Reads 用于播放 JSON,而不是 Anorm
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-19
  • 2013-02-04
  • 2018-09-12
  • 2015-05-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多