路由到Play中的静态文件! 2.0 [英] Route to static file in Play! 2.0

查看:99
本文介绍了路由到Play中的静态文件! 2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试路由到特定的静态文件,但是我尝试的所有操作都以错误结尾.

I'm trying to make a route to a specific static file but everything I'm trying ends with an error.

我做了3次不同的尝试:

I've made 3 different attempts:

1.

GET /file   staticFile:/public/html/file.html

我得到的错误:

Compilation error
string matching regex `\z' expected but `:' found

2.

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

我得到的错误:

Compilation error
Identifier expected

3.

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

我得到的错误:(这是最奇怪的)

The error I get: (and this is the weirdest)

Compilation error
not enough arguments for method at: (path: String, file: String)play.api.mvc.Call. Unspecified value parameter file.

关于第三个错误的怪异部分是,它在以下行中引发了另一个文件(app/views/main.scala.html):

The weird part about the 3rd error is that it's thrown in a different file (app/views/main.scala.html) on the following line:

<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")">

所有这些方法都可以在stackoverflow上的官方文档和/或线程中找到. 我在这里想念什么?

All of these methods were found in the official documentation and/or threads here on stackoverflow. What am I missing here?

谢谢.

推荐答案

IIRC,更改

<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")">

收件人

<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/", "main.css")">

我说的是你的第三次尝试

I am talking about your third attempt

此外,请多加注意/

编辑

GET /assets/main.css    controllers.Assets.at(path="/public", file="/stylesheets/main.css")

假设您的资源位于/public/stylesheets/main.css

Assuming your resource is at /public/stylesheets/main.css

这篇关于路由到Play中的静态文件! 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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