Play框架模板会自动导入模型._ [英] Play framework template automatically imports models._ among other things
问题描述
似乎在Play框架模板中
It seems like in Play framework templates,
有一个隐式的"@import models._"和"@import play.api.data.Form",因为我的代码是
there is an implicit "@import models._" and "@import play.api.data.Form" because my code:
@(title: String)(myForm: Form[User])
<!DOCTYPE html>
<html>
....
</html>
无需在第一行之后放置显式import语句即可工作.过去曾出现过此问题: https://groups.google. com/d/msg/play-framework/7FT68jd5asU/xYF0VNySJYcJ
works without having to put explicit import statements after the first line. This issue has been raised in the past: https://groups.google.com/d/msg/play-framework/7FT68jd5asU/xYF0VNySJYcJ
还隐式导入了哪些其他类/对象?
What other classes/objects are implicitly imported?
推荐答案
是的,Play Framework会自动在所有模板中添加一些import
语句.
You're right, Play Framework automatically add some import
statements to all templates.
您可以在Play源代码的PlaySettings
特征中找到这些默认导入":
You can find these "default imports" in the PlaySettings
trait from Play source code : https://github.com/playframework/Play20/blob/2.1.x/framework/src/sbt-plugin/src/main/scala/PlaySettings.scala
如果需要,可以在Build.scala中定义的项目设置中添加一些其他导入:
If you need to, you can add some additional imports in the project settings defined in your Build.scala :
val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA).settings(
templatesImport += "com.acme._"
)
这篇关于Play框架模板会自动导入模型._的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!