如何使用vertx解析查询参数?

noc*_*nal 7 java rest vert.x

I wanted to check if we can use getparam to parse start_time and end_time from the below request URL

https://[--hostname--]/sample_app/apthroughput/getAllControllers?start_time=<start time value>&end_time=<end time value>&label=<selected label>
Run Code Online (Sandbox Code Playgroud)

Ork*_*zen 7

查询字符串的解析非常简单,除非同一个查询参数有多个值。

e.g.: https://[--hostname--]/sample_app/apthroughput/getAllControllers?type=xxx&type=yyy
Run Code Online (Sandbox Code Playgroud)

在这种情况下,下面的代码有助于获取一种类型的所有参数 List<String>

这个答案给出了一个想法。从它复制:

HttpServerRequest request = RoutingContext.request();
MultiMap params =  request.params();
List<String> param = params.getAll("personId");
Here you can get list of personId. URI be like

localhost:8081/myApi?personId=1&personId=2&personId=3
Run Code Online (Sandbox Code Playgroud)


tse*_*ont 1

您可以获取参数 String 表示形式,但需要自己转换该值。