Context data

在一个请求的生命周期之内, 你可以将想要在handler之间共享的数据放在RoutingContext中进行传递.

下面的例子中,使用put添加数据, 使用get检索数据.

  1. router.get("/some/path").handler(routingContext -> {
  2. routingContext.put("foo", "bar");
  3. routingContext.next();
  4. });
  5. router.get("/some/path/other").handler(routingContext -> {
  6. String bar = routingContext.get("foo");
  7. // Do something with bar
  8. routingContext.response().end();
  9. });