简体   繁体   English

无法使用Anorm读取Integer列

[英]Can't read Integer column using Anorm

When I try to run (from Play Framework): 当我尝试运行时(来自Play Framework):

import play.api.db.DB
import anorm._
import org.joda.time.DateTime
import AnormExtensions._ // http://stackoverflow.com/a/11975107/11236
import play.api.Play.current
import java.util.Date

var stream = SQL("SELECT amiId, created, version FROM Amis WHERE created = {maxCreated}")
    .on("maxCreated" -> new Date(maxCreated.getMillis))
    .apply()

val map: Stream[Ami] = stream.map { ami =>
    val s: String = ami[String]("amiId")
    val date: Date = ami[Date]("created")

    // The following line throws a compilation error
    var version: Integer = ami[Integer]("version")

    new Ami(s, new DateTime(date), version)
}

I get a compilation error : could not find implicit value for parameter c: anorm.Column[Integer] 我得到一个编译错误: could not find implicit value for parameter c: anorm.Column[Integer]

What's the problem here? 这有什么问题? If I can read a Date , why can't I read an Integer ? 如果我能阅读Date ,为什么我不能阅读Integer

问题是我使用java java.lang.Integer而不是scala.Int

Such missing numeric conversion was fixed with release of Play 2.3. 这种缺失的数字转换是通过发布Play 2.3来修复的。 You may want upgrade to. 您可能需要升级到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM