1
我想了解這個錯誤:斯卡拉類型中的這個「_1」是什麼?
found : row.type (with underlying type _#TableElementType)
required: _1#TableElementType
貌似我非常接近,但「1」 _1#TableElementType
這是什麼?我可以將其中一個轉換成另一個嗎?
編輯:代碼的有用位上下文(播放+油滑):
例tableObject
abstract class GenericDAO[T <: AbstractTable[_]](...) {
def table: TableQuery[T]
def insert(model: T#TableElementType) = db run (table += model)
}
trait TableObject[T <: AbstractTable[_]] {
def rowFromJson(jsObject: JsObject): T#TableElementType
def dao(driver: JdbcProfile, db: Database): GenericDAO[T]
}
// Controller Action with an instance implementing `tableObject` above:
val tableObject = tableObjectFactory("test")
val row = tableObject.rowFromJson(request.body.asJson.get)
val dao = tableObject.dao(driver, db) // tableObject has a DOA extending GenericDAO
dao.insert(row)
:
object TestTable extends TableObject[Test] {
def dao(driver: JdbcProfile, db: Database) = new TestDAO(driver, db)
def rowFromJson(j: JsObject): TestRow = { TestRow(...) }
class TestDAO(...) extends GenericDAO[Test](driver, db) { ... }
}
我使用一個工廠來從URL是正確的:
object TableObjectFactory {
def tableObjectFactory(name: String) = {
name match {
case "test" => TestTable
case "projects" => ProjectsTable
case "people" => PeopleTable
...
}
}
}
你能分享你的代碼嗎? – BDR
我添加了提供上下文的代碼。 – JulienD
「tableObject」的類型究竟是什麼?你是否將它定義爲'val tableObject = TestTable'? –