如何使用play框架呈现简单的html页面?

nig*_*aph 5 playframework playframework-2.0

它是一种使用播放框架版本2呈现纯html文件的方法吗?我不想把它放在公共/文件夹中,因为稍后会添加一些动态信息.

Hai*_*mei 13

这是我的解决方案:

在路由中:我做了如下配置.

GET     /hello.html                 controllers.Assets.at(path="/public/html", file="hello.html")
GET     /public/javascripts/jquery-1.9.0.min.js     controllers.Assets.at(path="/public/javascripts", file="jquery-1.9.0.min.js")
GET     /public/stylesheets/bootstrap.css           controllers.Assets.at(path="/public/stylesheets", file="bootstrap.css")
Run Code Online (Sandbox Code Playgroud)

然后文件结构如下:

public->HTML->hello.html
public->javascripts->jquery-1.9.0.min.js
public->stylesheets->bootstrap.css
Run Code Online (Sandbox Code Playgroud)

对于hello.html,这是它的内容.

<!DOCTYPE html>    
<html lang="en">
<head>
    <meta charset="utf-8">
    <link rel='stylesheet' type='text/css' href='/public/stylesheets/bootstrap.css'>
</head>    
<body>
    <script src="/public/javascripts/jquery-1.9.0.min.js" type="text/javascript"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

完成这三个步骤后,您可以直接使用外部HTML.无需按照Play模板进行前端开发工作.所以现在,Play只负责后端.前端开发人员只需要操作此公共文件来进行开发.


bie*_*ior 12

当然,把你的整个静态HTML即.在index.scala.html并用最简单的方式:

public static Result index(){
    return ok(index.render());
}
Run Code Online (Sandbox Code Playgroud)

这是基础知识,你应该通过Play的文档和样本