我将main.scala.html放入资产中。我想不设置路由就打开它,因为它是静态的。
在controllers.Application中,我尝试这样
public static Result index() {
//return ok(index.render("Your new application is ready."));
return redirect("assets/main/main.scala.html");
}
在路线页面上,我尝试了这样
GET / controllers.Application.index
GET / *文件controllers.Assets.at(path =“ / assets”,文件)
如何修复我的代码以打开http://localhost:9000/assets/main/main.scala.html?
还是我应该尝试将html文件放在公用文件夹中?
最佳答案
1)如果它是静态的,则不应将其命名为main。scala
.html,而应仅命名为main.html
。 (不是强制性的,只是为了清楚是什么)
2)如注释中所述,您应该通过route.conf和Controller维护路由。但是您可以在不使用模板的情况下将文件作为资源加载。
GET /main controllers.Application.publicMain
public static Result publicMain{
return ok(Application.class.getResourceAsStream("/assets/main/main.html")).as("text/html");
}