【发布时间】:2014-11-03 18:58:57
【问题描述】:
我正在使用 Play 进行我的第一个项目!框架并阅读“Play for Java”Manning 书的第一章。
在第 1.5 节中,我们在应用程序/视图中构建了我们的第一个模板,它被称为 hello.scala.html
@(name:String)
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello</title>
</head>
<body>
<h1>Hello @name</h1>
</body>
</html>
为了引用这个模板,我在 app/Application.java 中使用了以下行
public class Application extends Controller {
public static Result hello(String name) {
return ok(views.html.hello.render(name));
}
我对 Java 还不是很熟悉,我正试图逐字逐句分解第三行的含义。
返回 ok --> 返回 HTTP OK 代码,到目前为止一切顺利。
views --> 这是否意味着查看 app/views 文件夹?或者它是存储在其他地方的视图路径的参考?
.html --> 这是数据类型吗?一个文件名?文件扩展名?如果模板被称为 hello.scala.htm 会改变吗?
.hello --> 这是引用文件的标题吗:hello.scala.html?
.render --> 所有模板都使用这个方法吗?
(name) --> 我假设这是引用 hello.scala.html 第一行中的参数
【问题讨论】: