Play Framework @routes.Assets.at 编译错误

2024-01-10

我正在使用 Play 2.4.0,并且我一直在尝试按照主页上的教程进行操作:https://playframework.com/ https://playframework.com/这是针对 Play 2.3 的,在解决了有关 Ebean ORM 从版本 2.3 到 2.4 的更改的几个问题后,我遇到了以下错误:

Compilation error

value at is not a member of controllers.ReverseAssets

My 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>
}

And my routes file:

# 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 https://www.playframework.com/documentation/2.4.0/Assets

所以...任何帮助将不胜感激。


好吧,总结一下解决方案:Play 允许您以两种不同的方式提供资产。 sbt-web 引入了老式和新的指纹识别方法。无论哪种情况,请确保在视图文件中使用正确的调用:

指纹资产

这是提供游戏中资产的推荐方式。指纹资产利用积极的缓存策略。您可以在此处阅读有关此主题的更多信息:https://playframework.com/documentation/2.4.x/Assets 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")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Play Framework @routes.Assets.at 编译错误 的相关文章

随机推荐