Play 1.2에서 @0 @0 equires of @0 extract of @20을 재생하고 있습니다.
-
12-12-2019 - |
문제
PLAY 1.2를 사용하는 경우,이 컨트롤러 내의 각 요청 전후에 메소드를 실행하기 위해 @before 또는 @after (및 다른 ...)가있는 컨트롤러 내부의 일부 메소드를 주석을 달 수있었습니다.
재생 2.0에서 어떻게 할 수 있습니까?
글로벌 대상에 대해 조금 읽었지만, 내가 찾고있는 것처럼 보입니다.또한 액션 컴포지션은 내가하고 싶은 것에 너무 복잡한 것처럼 보입니다.나는 더 간단한 것을 볼 수 있기를 바랍니다.
아이디어가 있습니까?
해결책
불행히도, Action Composition @Before
에 대해 사용해야합니다.@After
에 해당하는 것은 없습니다.
@After
의 경우 최종 조치가 끝나면 내 after
메소드를 작성합니다.이와 같은 것 :
public static Result index() {
....
Result result = ...;
return after(result);
}
protected static Result after(Result result) {
...
Result afterResult = ...,
return afterResult
}
. 다른 팁
public class Logging {
@With(LogAction.class)
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Logs {
}
public static class LogAction extends Action<Logs> {
private void before(Context ctx) {
System.out.println("Before action invoked");
}
private void after(Context ctx) {
System.out.println("After action invoked");
}
public F.Promise<Result> call(Http.Context context) throws Throwable {
before(context);
Promise<Result> result = delegate.call(context);
after(context);
return result;
}
}
}
.
컨트롤러에 @logs가있는 주석을 달기.
제휴하지 않습니다 StackOverflow