我有一个Play 2.0模板,其中包含以下第一行:
@(item: Option[Item] = None,
violations: java.util.Set[ConstraintViolation[Item]] = new util.HashSet[ConstraintViolation[Item]]())
@import java.util
@import javax.validation.ConstraintViolation
但无法找到ConstraintViolation
,我收到错误:
not found: type ConstraintViolation
bean验证API本身在应用程序中可用,因为我可以在控制器中使用它。如何在我的模板中导入它?
答案 0 :(得分:9)
使用完全限定名称,即@(item: Option[Item] = None,
violations: java.util.Set[javax.validation.ConstraintViolation[Item]] = new util.HashSet[javax.validation.ConstraintViolation[Item]]())
或添加到Build.scala中的常规模板导入,如下所示:
val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(
templatesImport += "javax.validation.ConstraintViolation"
)