【问题标题】:Constraints validation without Form with Play2.6使用 Play2.6 进行无表单约束验证
【发布时间】:2017-08-29 20:13:32
【问题描述】:

将播放框架从 2.5 升级到 2.6 后出现以下错误。 (它能够用 2.5 编译) 斯卡拉版本: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")

【问题讨论】:

    标签: scala playframework


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2014-12-20
      • 1970-01-01
      • 2017-06-24
      • 1970-01-01
      • 1970-01-01
      • 2017-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多