我有一个 Scala def,它从 HTTP POST 获取参数并解析数据。我正在从数据库中提取一个“作业”对象(在调试器中验证查询成功,并且参数与它们需要的一样)并且我正在尝试使用新参数更新该作业对象。但是,尝试分配值被证明是无用的,因为作业对象保留了所有原始值。
所有数据库对象都来自 Squeryl。下面的代码:
编辑:在下面添加了类和 Job 对象以帮助在此 Play 中提供上下文!应用程序
object Job {
def updateFromParams(params:Params) = {
val job = Job.get( params.get("job_id").toLong ).get
val comments = params.get("comments")
val startTime = parseDateTime(params.get("start_time") + " " + params.get("date"))
val endTime = parseDateTime(params.get("end_time") + " " + params.get("date"))
val clientId = params.get("client_id").toLong
val client = Client.get(clientId).get
val name = params.get("job_name")
val startAddressType = params.get("start_address_type")
var startLocationId:Option[Long] = None
val (startAddress, startCity, startProvince) = startAddressType match {
case "client" => getClientAddress(clientId)
case "custom" => (params.get("start_custom_address"),
params.get("start_custom_city"),
params.get("start_custom_province"))
case id => {
startLocationId = Some(id.toLong)
getLocationAddress(startLocationId.get)
}
}
job.comments -> comments
job.startTime -> startTime
job.endTime -> endTime
job.clientId -> clientId
job.name -> name
job.startAddressType -> startAddressType
job.startAddress -> startAddress
job.startCity -> startCity
job.startProvince -> startProvince
Job.update(job)
}
}
我很难过,因为如果我尝试job.name -> name
什么都没有发生,如果我尝试job.name = name
然后我得到一个 Scalareassignment to val
错误。尝试var name
而不是val name
.
这显然是我的语法问题,处理这个问题的正确方法是什么?谢谢!
更多信息:如果这有帮助,这里是我们 Play 中使用的 Job 类!应用程序:
class Job(
val id: Long,
@Column("name")
val name: String,
@Column("end_time")
val endTime: Timestamp,
@Column("start_time")
val startTime: Timestamp,
@Column("client_id")
val clientId: Long,
@Column("start_address_type")
var startAddressType:String,
@Column("start_address")
var startAddress: String,
/* LOTS MORE LIKE THIS */
) extends KeyedEntity[Long] {
}