本文整理了Java中io.vertx.ext.web.Route.setRegexGroupsNames
方法的一些代码示例,展示了Route.setRegexGroupsNames
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Route.setRegexGroupsNames
方法的具体详情如下:
包路径:io.vertx.ext.web.Route
类名称:Route
方法名:setRegexGroupsNames
[英]When you add a new route with a regular expression, you can add named capture groups for parameters.
However, if you need more complex parameters names (like "param_name"), you can add parameters names with this function. You have to name capture groups in regex with names: "p0", "p1", "p2", ...
For example: If you declare route with regex /(?[a-z])/(?[a-z]) and group names ["param_a", "param-b"] for uri /hello/world you receive inside pathParams() the parameter param_a = "hello"
[中]使用正则表达式添加新路由时,可以为参数添加命名的捕获组。
但是,如果需要更复杂的参数名称(如“param_name”),可以使用此函数添加参数名称。您必须在正则表达式中用名称命名捕获组:“p0”、“p1”、“p2”。。。
例如:如果您使用regex/(?[a-z])/(?[a-z])和组名[“param_a”,“param-b”]来声明路由,您将在pathParams()中收到uri/hello/world的参数param_a=“hello”
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testSetRegexGroupsNamesMethod() throws Exception {
List<String> groupNames = new ArrayList<>();
groupNames.add("hello");
Route route1 = router.getWithRegex("\\/(?<p0>[a-z]{2})");
route1.setRegexGroupsNames(groupNames);
route1.handler(routingContext -> routingContext
.response()
.setStatusCode(200)
.setStatusMessage(routingContext.pathParam("hello"))
.end());
testRequest(HttpMethod.GET, "/hi", 200, "hi");
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testRegexGroupsNamesWithMethodOverride() throws Exception {
List<String> groupNames = new ArrayList<>();
groupNames.add("FirstParam");
groupNames.add("SecondParam");
Route route = router.getWithRegex("\\/([a-z]{2})([a-z]{2})");
route.setRegexGroupsNames(groupNames);
route.handler(routingContext -> routingContext
.response()
.setStatusCode(200)
.setStatusMessage(routingContext.pathParam("FirstParam") + "-" + routingContext.pathParam("SecondParam"))
.end());
testRequest(HttpMethod.GET, "/aabb", 200, "aa-bb");
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testSetRegexGroupsNamesMethodWithUnorderedGroups() throws Exception {
List<String> groupNames = new ArrayList<>();
groupNames.add("firstParam");
groupNames.add("secondParam");
Route route1 = router.getWithRegex("\\/(?<p1>[a-z]{2})(?<p0>[a-z]{2})");
route1.setRegexGroupsNames(groupNames);
route1.handler(routingContext -> routingContext
.response()
.setStatusCode(200)
.setStatusMessage(routingContext.pathParam("firstParam") + "-" + routingContext.pathParam("secondParam"))
.end());
testRequest(HttpMethod.GET, "/bbaa", 200, "aa-bb");
}
代码示例来源:origin: vert-x3/vertx-web
@Test
public void testSetRegexGroupsNamesMethodWithNestedRegex() throws Exception {
List<String> groupNames = new ArrayList<>();
groupNames.add("firstParam");
groupNames.add("secondParam");
Route route1 = router.getWithRegex("\\/(?<p1>[a-z]{2}(?<p0>[a-z]{2}))");
route1.setRegexGroupsNames(groupNames);
route1.handler(routingContext -> routingContext
.response()
.setStatusCode(200)
.setStatusMessage(routingContext.pathParam("firstParam") + "-" + routingContext.pathParam("secondParam"))
.end());
testRequest(HttpMethod.GET, "/bbaa", 200, "aa-bbaa");
}
代码示例来源:origin: wang007/vertx-start
@Override
public Route setRegexGroupsNames(List<String> groups) {
return delegate.setRegexGroupsNames(groups);
}
}
代码示例来源:origin: io.vertx/vertx-rx-java
/**
* When you add a new route with a regular expression, you can add named capture groups for parameters. <br/>
* However, if you need more complex parameters names (like "param_name"), you can add parameters names with
* this function. You have to name capture groups in regex with names: "p0", "p1", "p2", ... <br/>
* <br/>
* For example: If you declare route with regex \/(?<p0>[a-z]*)\/(?<p1>[a-z]*) and group names ["param_a", "param-b"]
* for uri /hello/world you receive inside pathParams() the parameter param_a = "hello"
* @param groups group names
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.rxjava.ext.web.Route setRegexGroupsNames(List<String> groups) {
delegate.setRegexGroupsNames(groups);
return this;
}
代码示例来源:origin: vert-x3/vertx-rx
/**
* When you add a new route with a regular expression, you can add named capture groups for parameters. <br/>
* However, if you need more complex parameters names (like "param_name"), you can add parameters names with
* this function. You have to name capture groups in regex with names: "p0", "p1", "p2", ... <br/>
* <br/>
* For example: If you declare route with regex \/(?<p0>[a-z]*)\/(?<p1>[a-z]*) and group names ["param_a", "param-b"]
* for uri /hello/world you receive inside pathParams() the parameter param_a = "hello"
* @param groups group names
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.rxjava.ext.web.Route setRegexGroupsNames(List<String> groups) {
delegate.setRegexGroupsNames(groups);
return this;
}
代码示例来源:origin: io.vertx/vertx-web
@Test
public void testSetRegexGroupsNamesMethodWithUnorderedGroups() throws Exception {
List<String> groupNames = new ArrayList<>();
groupNames.add("firstParam");
groupNames.add("secondParam");
Route route1 = router.getWithRegex("\\/(?<p1>[a-z]{2})(?<p0>[a-z]{2})");
route1.setRegexGroupsNames(groupNames);
route1.handler(routingContext -> routingContext
.response()
.setStatusCode(200)
.setStatusMessage(routingContext.pathParam("firstParam") + "-" + routingContext.pathParam("secondParam"))
.end());
testRequest(HttpMethod.GET, "/bbaa", 200, "aa-bb");
}
代码示例来源:origin: io.vertx/vertx-web
@Test
public void testRegexGroupsNamesWithMethodOverride() throws Exception {
List<String> groupNames = new ArrayList<>();
groupNames.add("FirstParam");
groupNames.add("SecondParam");
Route route = router.getWithRegex("\\/([a-z]{2})([a-z]{2})");
route.setRegexGroupsNames(groupNames);
route.handler(routingContext -> routingContext
.response()
.setStatusCode(200)
.setStatusMessage(routingContext.pathParam("FirstParam") + "-" + routingContext.pathParam("SecondParam"))
.end());
testRequest(HttpMethod.GET, "/aabb", 200, "aa-bb");
}
代码示例来源:origin: io.vertx/vertx-web
@Test
public void testSetRegexGroupsNamesMethodWithNestedRegex() throws Exception {
List<String> groupNames = new ArrayList<>();
groupNames.add("firstParam");
groupNames.add("secondParam");
Route route1 = router.getWithRegex("\\/(?<p1>[a-z]{2}(?<p0>[a-z]{2}))");
route1.setRegexGroupsNames(groupNames);
route1.handler(routingContext -> routingContext
.response()
.setStatusCode(200)
.setStatusMessage(routingContext.pathParam("firstParam") + "-" + routingContext.pathParam("secondParam"))
.end());
testRequest(HttpMethod.GET, "/bbaa", 200, "aa-bbaa");
}
代码示例来源:origin: io.vertx/vertx-web
@Test
public void testSetRegexGroupsNamesMethod() throws Exception {
List<String> groupNames = new ArrayList<>();
groupNames.add("hello");
Route route1 = router.getWithRegex("\\/(?<p0>[a-z]{2})");
route1.setRegexGroupsNames(groupNames);
route1.handler(routingContext -> routingContext
.response()
.setStatusCode(200)
.setStatusMessage(routingContext.pathParam("hello"))
.end());
testRequest(HttpMethod.GET, "/hi", 200, "hi");
}
内容来源于网络,如有侵权,请联系作者删除!