Scala中的Play框架表单验证工作
跟随我的Signup对象,它在行“ mapping(”:“
对象形式中用于方法映射的参数;如果您想使用此方法,请使用“ _”
将其视为部分应用的功能”

case class UserRegistration(username: String, password1: String, password2: String)

val loginForm = Form(
 mapping(
   "username" -> email,
   "password1" -> text,
   "password2" -> text
 )
 (UserRegistration.apply)(UserRegistration.unapply)
 verifying ("Passwords must match",  => f.password1 == f.password2)
)

最佳答案

case class UserRegistration(username: String, password1: String, password2: String)

val loginForm = Form(
  mapping(
    "username" -> email,
    "password1" -> text,
    "password2" -> text
  )
  (UserRegistration.apply)(UserRegistration.unapply)
  verifying ("Passwords must match", f => f.password1 == f.password2)
)


您错过了("Passwords must match", f => f.password1 == f.password2)

10-04 10:10