java Play 框架 @routes.Assets.at 编译错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30562642/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 17:19:19  来源:igfitidea点击:

Play Framework @routes.Assets.at Compilation Error

javaplayframeworkjava-8playframework-2.4

提问by Daniel Romero

I'm using Play 2.4.0 and I've been trying to follow the tutorial from the main page: https://playframework.com/which is for Play 2.3 and after solving a couple of issues regarding changes in the Ebean ORM from version 2.3 to 2.4, I'm stuck with the following error:

我正在使用 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

My index.scala.html:

我的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 routesfile:

还有我的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)

I have this same example working ok with Play 2.3.9

我有同样的例子,可以在 Play 2.3.9 上正常工作

And I can't see anything different about working with public assets in the docs for the 2.4.0: https://www.playframework.com/documentation/2.4.0/Assets

在 2.4.0 的文档中,我看不出使用公共资产有什么不同:https: //www.playframework.com/documentation/2.4.0/Assets

So... any help would be appreciated.

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

回答by Roman

Alright, to sum up the solution: Play lets you serve your assets in two different ways. The old fashioned and the new fingerprinted method introduced with sbt-web. In either case make sure you use right call in your view files:

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

Fingerprinted assets

指纹资产

This is the recommended way to serve assets in play. Fingerprinted assets make use of an aggressive caching strategy. You can read more about this topic here: https://playframework.com/documentation/2.4.x/Assets

这是在游戏中提供资产的推荐方式。指纹资产利用积极的缓存策略。您可以在此处阅读有关此主题的更多信息:https: //playframework.com/documentation/2.4.x/Assets

routes config:

路由配置:

GET     /assets/*file               controllers.Assets.versioned(path="/public", file: Asset)

Make sure the type of fileis indicated as Asset

确保类型file表示为Asset

call in views:

调用视图:

@routes.Assets.versioned("an_asset")



Old fashioned assets

老式资产

This is basically the method used before the introduction of sbt-web.

这基本上是引入sbt-web之前使用的方法。

routes config:

路由配置:

GET     /assets/*file               controllers.Assets.at(path="/public", file)

call in views:

调用视图:

@routes.Assets.at("an_asset")