Java 在动作合成-播放框架内获取路径参数

Java 在动作合成-播放框架内获取路径参数,java,playframework,playframework-2.5,Java,Playframework,Playframework 2.5,我有一条路线 GET/students/:id/edit controller.students controller.edit(id:Long) 在点击控制器之前,我想做一些验证 @With(ValidStudentIdAction.class) public Result edit(long id) { // ... edit stuff } public class ValidStudentIdAction extends play.mvc.Action.Simple { pub

我有一条路线

GET/students/:id/edit controller.students controller.edit(id:Long)

在点击控制器之前,我想做一些验证

@With(ValidStudentIdAction.class)
public Result edit(long id) {
// ... edit stuff
}

public class ValidStudentIdAction extends play.mvc.Action.Simple {
    public CompletionStage<Result> call(Http.Context ctx) {
      long id receives the :id from request

      // now I know the id, I can verify if exist some Student with
      // this id, else return an error
      // ...

      return delegate.call(ctx);
    }
}
@With(ValidStudentIdAction.class)
公共结果编辑(长id){
//…编辑东西
}
公共类ValidStudentIdAction扩展play.mvc.Action.Simple{
公共CompletionStage调用(Http.Context ctx){
长id从请求接收:id
//现在我知道了id,我可以验证是否存在与
//此id,否则返回错误
// ...
返回委托呼叫(ctx);
}
}
问题是,如何从请求中获取
:id
?调用
ctx.request()
返回我
GET/students/{我想要的id}/edit
,但不指定获取此
:id
的方法。是否可以以可移植的方式获取
:id
,而无需执行一些不可移植的正则表达式


注意:我不是在处理查询参数,URL类似于
controller/id/action

,你知道吗?无法访问路径参数确实会降低动作合成的可能性。