Play 框架 @routes.Assets.at 编译错误 [英] Play Framework @routes.Assets.at Compilation Error

查看:31
本文介绍了Play 框架 @routes.Assets.at 编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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:

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 上也有同样的例子

I have this same example working ok with Play 2.3.9

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

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

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

So... any help would be appreciated.

推荐答案

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

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:

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

路由配置:

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

确保file的类型为Asset

调用视图:

@routes.Assets.versioned("an_asset")


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

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

路由配置:

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

调用视图:

@routes.Assets.at("an_asset")

这篇关于Play 框架 @routes.Assets.at 编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆