我有路线
GET /students/:id/edit controllers.StudentsController.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);
}
}
问题是,如何从请求中获取:id
?调用ctx.request()
会向我GET /students/{the id I want}/edit
返回,但docs没有指定获取此:id
的方法。是否可以以便携方式获取:id
而无需使用非便携式正则表达式?
注意:我没有处理查询参数,网址就像controller/id/action