我正在使用带有Java的playframework 2.2.0。如何从控制器操作中返回Not Modified?
Controller superClass中有几种方法:ok(),noContent()等,但不是notModified()。
查看播放的源代码,我可以看到:
val NotModified = SimpleResult(header = ResponseHeader(NOT_MODIFIED), body = Enumerator.empty,
connection = HttpConnection.KeepAlive)
在play.api.mvc.Results中。但是如何将SimpleResult包装在Java控制器可以返回的内容中呢?
该方法想要返回结果:
public interface Result {
scala.concurrent.Future<play.api.mvc.SimpleResult> getWrappedResult();
}
但我不知道如何从Java生成Future。 (我尝试使用scala.concurrent.Future $ .MODULE $ ...但是我的java代码看不到它)
答案 0 :(得分:1)
而不是像ok()那样的东西,试试这个:
return status(304, "Content not modified, dude.");
参考:http://www.playframework.com/documentation/2.2.0/JavaActions
看起来像play.api.mvc.Results,在Scala API中,实际上有一个NotModified生成器,但Java API没有。如果您使用Java API,则无法使用Scala API中的任何内容。似乎Java API是Play Framework的不受欢迎的孩子。
总之,返回状态304比尝试从Play Scala API中拖入组件并从Java中使用它们要简单得多。 HTTP响应代码304 =未修改的内容。
请在此处查看代码列表:http://www.w3.org/Protocols/HTTP/HTRESP.html