在我的Play中定义表单!编译器吐出这个奇怪的错误时控制器:overloaded method value mapping with alternative:...[a bunch of crap]...Error occurred in an application involving default arguments
。
这是代码,我不确定原因是什么:
val jobForm: Form[Job] = Form(
mapping(
"id" -> of[Long],
"end_time" -> text(minLength = 3),
"start_time" -> text(minLength = 3),
"client_id" -> of[Long],
"start_address_type" -> text,
"start_address" -> text(minLength = 3),
"start_city" -> text(minLength = 3),
"start_province" -> text(minLength = 2),
"start_lat" -> optional(text),
"start_lng" -> optional(text),
"comments" -> text,
"created" -> text,
"modified" -> text,
"canceled" -> of[Boolean],
"started" -> of[Boolean],
"completed" -> of[Boolean],
"user_id" -> optional(of[Long]),
"start_order" -> optional(number),
"end_order" -> optional(number),
"account_id" -> of[Long]
)(Job.apply)(Job.unapply)
)
答案 0 :(得分:4)
看看Play! 2.0来源。看起来每个mapping()
最多只能有18个参数,所以我必须开始嵌套并创建新的案例类。结果如下:
val jobForm: Form[JobSimple] = Form(
mapping(
"id" -> of[Long],
"end_time" -> text(minLength = 3),
"start_time" -> text(minLength = 3),
"client_id" -> of[Long],
"location" -> mapping(
"start_address_type" -> text,
"start_address" -> text(minLength = 3),
"start_city" -> text(minLength = 3),
"start_province" -> text(minLength = 2),
"start_lat" -> optional(text),
"start_lng" -> optional(text)
)(JobLocation.apply)(JobLocation.unapply),
"comments" -> text,
"created" -> text,
"modified" -> text,
"canceled" -> of[Boolean],
"started" -> of[Boolean],
"completed" -> of[Boolean],
"user_id" -> optional(of[Long]),
"start_order" -> optional(number),
"account_id" -> of[Long]
)(JobSimple.apply)(JobSimple.unapply)
)