xxx.scala:65: error: too many elements for tuple: 24, allowed: 22
實例:
import slick.lifted.Tag
import slick.jdbc.MySQLProfile.api._
import scala.concurrent.Await
import scala.concurrent.duration.Duration
import scala.collection.JavaConversions._
import java.util.List
case class Server(
id: Int,
serverCode: String,
imageHash: String,
name: String,
gender: String,
education: String,
birthday: String,
mobileTelephone: String,
otherTelephone: String,
identityCard: String,
politicalStatus: String,
nation: String,
agencyId : Int,
nativeProvinceId: Int,
nativeCityId: Int,
nativeCountyId: Int,
provinceId: Int,
cityId: Int,
countyId: Int,
address: String,
createDatetime: String,
identity: String,
isEnable: Boolean,
backup: String
)
class Servers(tag: Tag) extends Table[Server](tag, "servers") {
def id = column[Int]("id", O.PrimaryKey, O.AutoInc, O.SqlType("int"))
def serverCode = column[String]("server_code", O.Unique, O.Length(32), O.SqlType("char"))
def imageHash = column[String]("imageHash", O.Length(32), O.Default("00000000000000000000000000000000"), O.SqlType("char"))
def name = column[String]("name", O.Length(20), O.SqlType("varchar"))
def gender = column[String]("gender", O.Length(4), O.SqlType("varchar"))
def education = column[String]("education", O.Length(8), O.SqlType("varchar"))
def birthday = column[String]("birthday", O.SqlType("datetime"))
def mobileTelephone = column[String]("mobile_telephone", O.Length(16), O.SqlType("varchar"))
def otherTelephone = column[String]("other_telephone", O.Length(32), O.SqlType("varchar"))
def identityCard = column[String]("identity_card", O.Length(18), O.SqlType("char"))
def politicalStatus = column[String]("political_status", O.Length(8), O.SqlType("varchar"))
def nation = column[String]("nation", O.Length(12), O.SqlType("varchar"))
def agencyId = column[Int]("agency_id")
def nativeProvinceId = column[Int]("native_province")
def nativeCityId = column[Int]("native_city")
def nativeCountyId = column[Int]("native_county")
def provinceId = column[Int]("province")
def cityId = column[Int]("city")
def countyId = column[Int]("county")
def address = column[String]("address", O.Length(128), O.SqlType("varchar"))
def createDatetime = column[String]("create_datetime", O.SqlType("datetime"))
def identity = column[String]("identity", O.Length(16))
def isEnable = column[Boolean]("is_enable")
def backup = column[String]("backup", O.SqlType("text"))
def * = (id, serverCode, imageHash, name, gender, education, birthday, mobileTelephone, otherTelephone, identityCard, politicalStatus,
nation, agencyId, nativeProvinceId, nativeCityId, nativeCountyId, provinceId, cityId, countyId, address, createDatetime,identity,isEnable, backup) <> (Server.tupled, Server.unapply)
}
解決方法:https://github.com/underscoreio/slickless
1.導入入 slickless.jar
2.引入類
importshapeless.{HList,::,HNil,Generic }
importslickless._
3.
def * = (id :: ... :: HNil).mappedWith(Generic[Server])
數據庫操作實例
def getAll() : List[Demand_2] ={ val result = Await.result(db.run( (for{ d <- demands e <- employers if d.employerId === e.id } yield (d.id :: d.employerId :: d.demandSource :: d.demandType :: d.serviceType :: d.level :: d.serviceStartTime :: d.serviceEndTime :: d.provinceId :: d.cityId :: d.countyId :: d.area :: d.address :: d.detail :: d.isEnable :: d.state :: d.serviceStartDate :: d.serviceEndDate :: d.createTime :: d.lastModifyTime :: d.longitude :: d.latitude :: e.name :: e.tel :: e.userNum :: HNil).mappedWith(Generic[Demand_2]) ).result), Duration.Inf).toList return result; }