gpt4 book ai didi

playframework-2.0 - Play 1.2中@Before和@After的Play 2.0等效项是什么?

转载 作者:行者123 更新时间:2023-12-04 03:39:10 25 4
gpt4 key购买 nike

当我使用Play 1.2时,我可以使用@Before或@After(以及其他...)在任何 Controller 内注释一些方法,以便在此 Controller 内的每个请求之前或之后执行一个方法。

如何在Play 2.0中做到这一点?

我读了一些有关Global对象的信息,但这似乎不是我想要的。另外, Action 组合对于我想做的事情似乎太复杂了。我希望看到更简单的东西。

有任何想法吗?

最佳答案

不幸的是,您必须将action composition用作@Before,而@After没有等效项。

对于@After,我将在end操作结束时编写自己的after方法;像这样的东西:

public static Result index() {
....
Result result = ...;
return after(result);
}

protected static Result after(Result result) {
...
Result afterResult = ...,
return afterResult

}

关于playframework-2.0 - Play 1.2中@Before和@After的Play 2.0等效项是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12683176/

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