gpt4 book ai didi

java - Play Java 中的 @With 注解

转载 作者:行者123 更新时间:2023-11-30 06:55:32 28 4
gpt4 key购买 nike

我不明白 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时,首先会调用VerboseActioncall方法。因此,在此示例中,首先 Logger.info 将写入一些信息消息,然后稍后将完成 ok 响应。

关于java - Play Java 中的 @With 注解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41907433/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com