Routing with regular expressions

正则还可以被使用在URI路径的匹配上:

  1. Route route = router.route().pathRegex(".*foo");
  2. route.handler(routingContext -> {
  3. // This handler will be called for:
  4. // /some/path/foo
  5. // /foo
  6. // /foo/bar/wibble/foo
  7. // /foo/bar
  8. // But not:
  9. // /bar/wibble
  10. });

还有一种做法是,正则可以在创建route时进行指定.

  1. Route route = router.routeWithRegex(".*foo");
  2. route.handler(routingContext -> {
  3. // This handler will be called same as previous example
  4. });