我不明白 Play Java 中 @With
注释的含义。
我们有the same question在 StackOverflow 中似乎是 Play1,而不是 Play2。
而在Play最新版本的文档中,我看到了这个例子。
@With(VerboseAction.class)
public Result verboseIndex() {
return ok("It works!"); }
这是什么意思?在上面的例子中,带注解和不带注解有什么区别?
最佳答案
很明显@With用于组合Actions:
public class VerboseAction extends play.mvc.Action.Simple {
public CompletionStage<Result> call(Http.Context ctx) {
Logger.info("Calling action for {}", ctx);
return delegate.call(ctx);
}
}
您可以使用 @With
注释将操作方法提供的代码与另一个 play.mvc.Action
组合起来:
@With(VerboseAction.class)
public Result verboseIndex() {
return ok("It works!");
}
因此,当调用verboseIndex
时,首先会调用VerboseAction
的call
方法。因此,在此示例中,首先 Logger.info
将写入一些信息消息,然后稍后将完成 ok
响应。
关于java - Play Java 中的 @With 注解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41907433/