我有两个这样的案例类。
case class Company(name: String, address: Address)
case class Address(address1: String, address2: String,
city: String, state: String,
zip:String, country: String)
在我的Application.scala中,我定义了以下内容。
[1]. val companyForm = Form(of(Company.apply _, Company.unapply _)(
"name" -> text,
"address" -> mapping(
"address1" -> nonEmptyText,
"address2" -> text,
"city" -> nonEmptyText,
"state" -> nonEmptyText,
"zip" -> nonEmptyText,
"country" -> nonEmptyText
)(Address.apply)(Address.unapply)
)
)
[2]. val companyForm = Form(mapping(
"name" -> text,
"address" -> mapping(
"address1" -> nonEmptyText,
"address2" -> text,
"city" -> nonEmptyText,
"state" -> nonEmptyText,
"zip" -> nonEmptyText,
"country" -> nonEmptyText
)(Address.apply)(Address.unapply)
)(Company.apply, Company.unapply)
)
现在[1]适用于我,但当我尝试将其转换为[2]时,它会给我以下错误:
方法映射的参数太多:(apply:(String,models.Address)=> R)(unapply:R => Option [(String,models.Address)])play.api.data.Mapping [R]。
请告诉我我做错了什么。提前谢谢。
答案 0 :(得分:1)
由于methode of()
已弃用,您的表单必须如下所示:
val companyForm = Form(
mapping(
"name" -> text,
"address" -> mapping(
"address1" -> nonEmptyText,
"address2" -> text,
"city" -> nonEmptyText,
"state" -> nonEmptyText,
"zip" -> nonEmptyText,
"country" -> nonEmptyText
)(Address.apply)(Address.unapply)
)(Company.apply)(Company.unapply)
)
所以您的问题出现在Company.Apply and Company.unapply
方法