簡體   English   中英

無法使用Anorm讀取Integer列

[英]Can't read Integer column using Anorm

當我嘗試運行時(來自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)
}

我得到一個編譯錯誤: could not find implicit value for parameter c: anorm.Column[Integer]

這有什么問題? 如果我能閱讀Date ,為什么我不能閱讀Integer

問題是我使用java java.lang.Integer而不是scala.Int

這種缺失的數字轉換是通過發布Play 2.3來修復的。 您可能需要升級到。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM