这个问题已经在这个网站上被问过很多次了,但我仍然无法弄清楚答案。我正在尝试将表单映射到我拥有的案例类,这是案例类:
case class MapVitalSign(id:Long,name:String,
lowerBoundComplicationId:Long, upperBoundComplicationId:Long,
lowerBound:Double,upperBound:Double) extends VitalSign(
id,name,
lowerBoundComplicationId,upperBoundComplicationId,
lowerBound,upperBound)
这是我试图将其映射到的代码。
val vitalSignForm: Form[MapVitalSign] = Form(
mapping(
"id" -> ignored(Long),
"name" -> text,
"lowerBoundComplicationId" -> number,
"upperBoundComplicationId" -> number,
"lowerBound" -> number,
"upperBound" -> number)
((id,name,lowerBoundComplicationId,
upperBoundComplicationId,lowerBound,
upperBound) => MapVitalSign(id,name,
lowerBoundComplicationId.toLong,
upperBoundComplicationId.toLong,lowerBound.toDouble,
upperBound.toDouble),
(v:MapVitalSign) => Some(v.id,v.name,v.lowerBoundComplicationId.toInt,v.upperBoundComplicationid.toInt, lowerBound.toInt,upperBound.toInt) )
)
我的映射错误发生在哪里,据我所知,一切似乎都映射到正确的类型,并且争论的数量是正确的。是否与最初忽略的“id”字段有关(因为我的 posgres db 没有生成一个)?