Playframework 在Play Framework 2.3中,如何从控制器操作服务静态资产?
在我的应用程序中,我需要提供公用文件夹中的静态文件。出于某些原因,我必须从Java控制器的动作中执行 我想到的第一个解决方案是:Playframework 在Play Framework 2.3中,如何从控制器操作服务静态资产?,playframework,playframework-2.3,Playframework,Playframework 2.3,在我的应用程序中,我需要提供公用文件夹中的静态文件。出于某些原因,我必须从Java控制器的动作中执行 我想到的第一个解决方案是: public class Central extends Controller { public static Result index() { return Assets.at("/public", "central/index.html", false); } } 但是Assets.at方法返回类型是play.api.mvc
public class Central extends Controller {
public static Result index() {
return Assets.at("/public", "central/index.html", false);
}
}
但是Assets.at
方法返回类型是play.api.mvc.Action
有没有办法将其转换为类型play.mvc.Result
或者通过其他优雅的方式从Java控制器操作中提供静态文件?更改方法返回类型。 像这样:
public class Central extends Controller {
public static play.api.mvc.Action<play.api.mvc.AnyContent> index() {
return Assets.at("/public", "central/index.html", false);
}
}
公共类中央扩展控制器{
public static play.api.mvc.Action index(){
返回Assets.at(“/public”,“central/index.html”,false);
}
}
我为你找到了答案:为什么你想要结果而不是行动?结果不能在操作外部使用。我可以,我想我应该从index()操作返回结果。但是我不知道play.api.mvc.Action有什么用。