在我的Play Scala Project
我的表单中有超过18
个字段。我从输入type
submit
插入了一个表单值到DB
如果字段是少于18.如果我在18
中添加了超过form mapping
个字段,则会显示如下错误
missing arguments for method unapply in object EmployeeRegister; follow this method with `_' if you want to treat it as a partially applied function
控制器/ Employees.scala
val employeeForm = Form(
mapping(
"employeeid" -> ignored(None: Option[Int]),
"employeename" -> nonEmptyText,
"employeedesc" -> nonEmptyText,
.....
.....
"languages" -> list(number)
)(models.EmployeeRegister.apply)(models.EmployeeRegister.unapply))
模型/ Employee.scala
case class EmployeeRegister(
employeeid: Option[Int] = None,
employeename: String,
employeedesc: String,
.....
......
languages: List[Int]
)
我尝试了什么
我使用nested values
概念添加了超过18
个字段。它没有显示任何错误,但form submission
没有工作它转发到同一页面
使用此error handling
代码。
employeeForm.bindFromRequest.fold(
formWithErrors => BadRequest(html.employeeRegisterForm(formWithErrors),
employee => {
....
...
}
嵌套值
控制器/ Employees.scala
val employeeForm = Form(
mapping(
"employeeid" -> ignored(None: Option[Int]),
"employeename" -> nonEmptyText,
"employeedesc" -> nonEmptyText,
.....
.....
"os" -> mapping(
"operatingsystem" -> text,
"osversion" -> text,
"osbit" -> text
)(models.OS.apply)(models.OS.unapply),
"languages" -> list(number)
)(models.EmployeeRegister.apply)(models.EmployeeRegister.unapply))
模型/ employee.scala
case class EmployeeRegister(
employeeid: Option[Int] = None,
employeename: String,
employeedesc: String,
.....
......
os:OS,
languages: List[Int]
)
case class OS(
operatingsystem: String,
osversion: String,
osbit:String
)