玩JAVA通过anotation将请求参数传递给@

玩JAVA通过anotation将请求参数传递给@,java,playframework,annotations,playframework-2.2,Java,Playframework,Annotations,Playframework 2.2,我有这样的路线: GET /job$id<[0-9]+>/ controllers.Jobs.index(id) POST /job$id<[0-9]+>/done controllers.Jobs.done(id) POST /job$id<[0-9]+>/update controllers.Jobs.update(id) DELETE /job$id<[0-9]+>/remove

我有这样的路线:

  GET     /job$id<[0-9]+>/        controllers.Jobs.index(id)
  POST    /job$id<[0-9]+>/done    controllers.Jobs.done(id)
  POST    /job$id<[0-9]+>/update  controllers.Jobs.update(id)
  DELETE  /job$id<[0-9]+>/remove  controllers.Jobs.remove(id)
然后我尝试通过“@With()”注释来保护我的所有操作,但我需要将“Id”参数传递给我的安全方法,因此我编写了如下smth:

@With(IsOwner.class)
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Owner {
    long value() default 0;
}

public static class IsOwner extends Action<Owner>{
    @Override
    public Promise<SimpleResult> call(Context ctx) throws Throwable {

        if(!isOwner(configuration.value())){
            return Promise.pure(redirect(..));
        }
        return delegate.call(ctx);
    }
}
我看到的另一种方法是从IsOwner.call()中的上下文获取参数

请给我一个建议或良好的做法,这种情况下


谢谢。

我遇到了这个问题,并提出了一个播放扩展,它将所有url参数公开为公共请求参数。。。您可以在这里查看=>

基本上,你必须从我的全球课程扩展

干杯


阿尔贝托

嗯。。注释变量只能是常量。所以我需要在call()方法中获取路径参数的方法。谢谢。但我不认为这是最好的方法。可能不是。。。但没有其他办法,至少目前是这样:)。
@With(IsOwner.class)
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Owner {
    long value() default 0;
}

public static class IsOwner extends Action<Owner>{
    @Override
    public Promise<SimpleResult> call(Context ctx) throws Throwable {

        if(!isOwner(configuration.value())){
            return Promise.pure(redirect(..));
        }
        return delegate.call(ctx);
    }
}
@Security.Authenticated(Secured.class)

@Owner(id) //**this part I want to work**
public class Jobs extends Controller {

  //@Owner(id) - or at list there
  public static Result index(Long Id){
    //I have too many Actions and don't want to do every time this
    /*if(!Secured.isOwnerMethod(Id)){
      return forbidden();
    }*/         
    return ok();        
  }