gpt4 book ai didi

scala - 方法映射的参数太多 : (apply: (String, models.Address) => R)(unapply : R => Option[(String, models.Address)])play.api.data.Mapping[R]

转载 作者:行者123 更新时间:2023-12-01 21:57:20 25 4
gpt4 key购买 nike

我有两个这样的案例类。

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 ].

请告诉我我做错了什么。提前致谢。

最佳答案

由于 method 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 和 Company.unapply 方法

关于scala - 方法映射的参数太多 : (apply: (String, models.Address) => R)(unapply : R => Option[(String, models.Address)])play.api.data.Mapping[R],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16390285/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com