我使用Play 2.4.0并且我一直在尝试按照主页中的教程进行操作:https://playframework.com/ 这是针对Play 2.3,在解决了有关Ebean ORM从版本2.3到2.4的变化的几个问题之后,我遇到了以下错误:
Compilation error
value at is not a member of controllers.ReverseAssets
我的index.scala.html
:
@(message: String)
@main("Welcome to Play") {
<script type='text/javascript' src="@routes.Assets.at("javascripts/index.js")"></script>
<form action="@routes.Application.addPerson()" method="post">
<input type="text" name="name" />
<button>Add Person</button>
</form>
<ul id="persons">
</ul>
}
我的routes
文件:
# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~
# Home page
GET / controllers.Application.index()
POST /person controllers.Application.addPerson()
GET /persons controllers.Application.getPersons()
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
我有这个相同的例子与Play 2.3.9一起工作
在2.4.0的文档中,我无法看到与使用公共资产有任何不同之处:https://www.playframework.com/documentation/2.4.0/Assets
所以......任何帮助都会受到赞赏。
答案 0 :(得分:65)
好的,总结解决方案:Play可让您以两种不同的方式提供资源。用sbt-web引入的老式和新的指纹方法。在任何一种情况下,请确保在视图文件中使用正确的调用:
这是投放资产的推荐方式。指纹识别资产利用积极的缓存策略。您可以在此处详细了解此主题:https://playframework.com/documentation/2.4.x/Assets
路线配置:
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
确保file
的类型显示为Asset
在观看中调用:
@routes.Assets.versioned("an_asset")
这基本上是在引入sbt-web之前使用的方法。
路线配置:
GET /assets/*file controllers.Assets.at(path="/public", file)
在观看中调用:
@routes.Assets.at("an_asset")