我正在尝试将现有的 .NET MVC 应用程序移植到 Java Play。这个应用程序使用了 ASP 母版页,我试图通过使用 Play 模板来复制这个概念。
我在这里遵循了文档: https ://www.playframework.com/documentation/2.5.x/JavaTemplateUseCases
如果我复制/粘贴示例,一切都会编译。但是由于某种原因,替换我自己的参数会导致此错误...
turkish:myApp adam$ ./bin/activator clean compile
[info] Loading project definition from /Users/adam/myApp/myApp/project
[info] Set current project to myApp (in build file:/Users/adam/myApp/myApp/)
[success] Total time: 0 s, completed Nov 30, 2016 10:11:09 AM
[info] Updating {file:/Users/adam/myApp/myApp/}root...
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[info] Compiling 28 Scala sources and 9 Java sources to /Users/adam/myApp/myApp/target/scala-2.11/classes...
[error] /Users/adam/myApp/myApp/app/views/Shared/Documentation.scala.html:1: not found: value AdditionalPageIncludes
[error] @(AdditionalPageIncludes: Html)(SubNavigation: Html)(SectionTitle: Html)(TableOfContentsPlaceHolder: Html)(ArticlePlaceHolder: Html)
[error] ^
[error] one error found
[error] (compile:compileIncremental) Compilation failed
[error] Total time: 13 s, completed Nov 30, 2016 10:11:21 AM
如示例所示,我在第一行声明了 (?) 我的参数:
@(AdditionalPageIncludes: Html)(SubNavigation: Html)(SectionTitle: Html)(TableOfContentsPlaceHolder: Html)(ArticlePlaceHolder: Html)
昨天我用一个类似的页面完成了这个确切的过程,不知何故最终得到了编译。它似乎是先编译视图,然后通过激活器运行干净编译的某种组合。这在今天似乎行不通。
似乎每个项目构建后都会留下许多工件,这就是我每次都运行干净编译的原因(这需要很长时间)。我有一种感觉,我只是不了解这些模板/参数应该如何工作。
这是在使用 Java/Scala/Play 时使用参数定义模板的正确方法吗?似乎它期望使用此参数而不是声明它。
编辑:
这是正确编译的模板(views/Shared/PublicMain.scala.html):
@(AdditionalPageIncludes: Html)(MainContent: Html)
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="description" content="" />
<link rel="Stylesheet" type="text/css" href="/public/stylesheets/reset.css" />
<link rel="Stylesheet" type="text/css" href="/public/stylesheets/public-main.css" />
<link rel="Stylesheet" type="text/css" href="/public/stylesheets/ui.css" />
<link rel="Stylesheet" type="text/css" href="/public/stylesheets/notification.css" />
<link href='//fonts.googleapis.com/css?family=Source+Sans+Pro:400,700,400italic' rel='stylesheet' type='text/css'>
<script type="text/javascript" src="/public/javascripts/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="/public/javascripts/jquery-ui-1.8.16.custom.min.js"></script>
@AdditionalPageIncludes
<script type="text/javascript" src="/public/javascripts/Analytics.js"></script>
</head>
<body>
@MainContent
</body>
</html>
这是编译失败的模板(views/Shared/DocumentationMain.scala.html):
@(AdditionalPageIncludes: Html)(SubNavigation: Html)(SectionTitle: Html)(TableOfContentsPlaceHolder: Html)(ArticlePlaceHolder: Html)
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title></title>
<link rel="Stylesheet" type="text/css" href="/public/stylesheets/reset.css" />
<link rel="Stylesheet" type="text/css" href="/public/stylesheets/base.css" />
<link rel="Stylesheet" type="text/css" href="/public/stylesheets/navigation.css" />
<link rel="Stylesheet" type="text/css" href="/public/stylesheets/widget.css" />
<link rel="Stylesheet" type="text/css" href="/public/stylesheets/profile.css" />
<link rel="Stylesheet" type="text/css" href="/public/stylesheets/ui.css" />
<link rel="Stylesheet" type="text/css" href="/public/stylesheets/notification.css" />
<link rel="Stylesheet" type="text/css" href="/public/stylesheets/documentation.css" />
<link rel="Stylesheet" type="text/css" href="/public/stylesheets/jquery.ui.all.css" />
<link href='//fonts.googleapis.com/css?family=Source+Sans+Pro:400,700,400italic' rel='stylesheet' type='text/css' />
<!--AdditionalPageIncludes-->
</head>
<body>
<div id="Header">
<div id="HeaderContent">
<span style="float:right; line-height:30px; font-size:1.5em; vertical-align:middle; color:#eee; font-weight:bold;">Documentation</span>
<div style="height:30px;"></div>
<div style="clear:both;"></div>
</div>
</div>
<div id="SectionHeader">
<div id="SectionHeaderContent">
<div id="SectionNavigation">
<!--SubNavigation-->
</div>
<h2><!--SectionTitle--></h2>
</div>
</div>
<div id="Content">
<div class="WidgetCanvas RoundCorners">
<div style="clear:both;"></div>
</div>
</div>
</body>
</html>