[英]Scala Play framework Forms, type not automatically inferred for a tuple parameter
I'm learning to use forms in Play Framework and I have the following problem. 我正在学习在Play Framework中使用表格,但遇到以下问题。 I have a case class like this: 我有一个这样的案例类:
case class Part(id: Option[Int],
description: String,
created: DateTime)
and I'm trying to retrieve/populate it from/to a Play Form defined like this: 我正在尝试从这样定义的播放表单中检索/填充它:
val addPartForm = Form(
mapping(
"description" -> text
)(tp => Part.apply(id = None, description = tp._1, created = new DateTime()))
(pt => (pt.description)))
so basically I'm trying to provide a custom mapping functions as the usual Part.apply and Part.unapply versions are not an exact match/map. 所以基本上我想提供一个自定义映射功能,因为通常的Part.apply和Part.unapply版本不是完全匹配/映射。 When I try to compile this code it gives an error on the tp
parameter saying missing parameter type
. 当我尝试编译此代码时,它在tp
参数上显示错误,提示missing parameter type
。 Why the type for tp
can't be inferred automatically? 为什么不能自动推断出tp
的类型? If I provide the type for tp
explicitly it does compile. 如果我为tp
提供类型,则可以编译。 Thank you for your help. 谢谢您的帮助。
Try describing the resulting tuple as follows: 尝试如下描述生成的元组:
val addPartForm = Form(
mapping(
"description" -> text
)((description) => Part(id = None, description = description, created = new DateTime()))
(part => Some(part.description))
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.