不带Play2.6表单的约束验证

时间:2017-07-26 09:42:00

标签: scala playframework

升级后的播放框架从2.5升级到2.6后出现以下错误。 (它可以用2.5编译) Scala版本:2.11.8

ambiguous reference to overloaded definition,
[error] both method emailAddress in trait Constraints of type => play.api.data.validation.Constraint[String]
[error] and  method emailAddress in trait Constraints of type (errorMessage: String)play.api.data.validation.Constraint[String]
[error] match argument types (String)
[error] Constraints.emailAddress("test@sample.com")
                    ^

有没有办法在Play 2.6的Constraints下使用方法?

import play.api.data.validation._

val result = Constraints.emailAddress("test@sample.com")

1 个答案:

答案 0 :(得分:0)

emailAddress是一种内部调用另一个重写方法emailAddress(errorMessage:String =" error.email")方法的方法,所以如果你调用带有编译错误的参数的emailAddress,那么你可以测试它像这样

val result = Constraints.emailAddress

    result("test@sample.com")