【问题标题】:How to serve static asset from a controller action in Play Framework 2.3?如何从 Play Framework 2.3 中的控制器操作提供静态资产?
【发布时间】:2014-08-27 21:02:12
【问题描述】:

在我的应用程序中,我需要从公共文件夹中提供一个静态文件。由于某些原因,我必须通过 Java 控制器操作来完成。

我想到的第一个解决方案是:

public class Central extends Controller {
     public static Result index() {
         return Assets.at("/public", "central/index.html", false);
     }
}

但是Assets.at方法返回类型是play.api.mvc.Action<play.api.mvc.AnyContent>

有没有办法将其转换为类型 play.mvc.Result

或者任何其他优雅的方式来从 Java 控制器操作中提供静态文件?

【问题讨论】:

  • 我为你找到了这个答案:stackoverflow.com/questions/8305853/…
  • 为什么要结果而不是行动?结果不能用于外部操作。
  • 我可以而且我想我应该从我的 index() 操作中返回 Result。但我不知道我可以用 play.api.mvc.Action 做什么。

标签: playframework playframework-2.3


【解决方案1】:

改变你的方法返回类型。 像这样:

public class Central extends Controller {
     public static play.api.mvc.Action<play.api.mvc.AnyContent> index() {
         return Assets.at("/public", "central/index.html", false);
     }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-05
    • 2012-08-09
    • 1970-01-01
    • 2015-05-09
    • 2015-02-05
    • 2013-12-29
    • 2014-03-27
    相关资源
    最近更新 更多