渡槽布线行为意外结果

问题描述

我正在尝试使用 dart 中的 Aqueduct 创建后端服务器。我正在尝试创建一个资源控制器来处理帐户问题。

路由代码是这样的;

router
        .route("/$apiEntryPointUrl/account/:operation").link(() => AccountController(context,authServer));

当我尝试像这样测试路由器路径变量时;

   @Operation.post("asdf")
  Future<Response> test() async {
    return Response.ok("testsuccess");
  }

  @Operation.post("operation")
  Future<Response> test5() async {
    return Response.ok("bugsuccess");
  }

  @Operation.post("test3")
  Future<Response> test2() async {
    return Response.ok("testsucces3333s");
  }

当我添加 Operation.post("operation") 作为路径变量时,我传递给变量的任何东西都会进入这个函数。如果我发出一个喜欢 /account/tes2 的帖子请求,它会调用 test5() 函数。这是正常的吗?我是否缺少一些基础知识?

解决方法

实际上是的,这是正常且有意的。如果您在路由器中指定类似这样的内容:'/account/:operation' 或 '/account/:id' 那么您最终会得到一个通配符,在这些示例中是 'operation' 或 'id'。 运算符“:”充当通配符操作。这意味着实际上对“/account/tes2”等路由的 API 调用将自动调用通配符路由。