问题描述
我是sparkjava的新手。我想使用spark java读取我的请求参数,但是我无法找到正确的语法。请帮助我。下面是我的路由方法和客户端调用:
$ b
我的客户端请求url:
/ smartapp / getDataViewModelConfig?collId = 123'
路线方式:
get(smartapp / getDataViewModelConfig /:id,application / json,(request,response)
- > {
String id = request.params(:id );
}
'id'字段在这里返回null。这里出了什么问题?
如果您必须使用像 / smartapp / getDataViewModelConfig这样的URL? collId = 123
你必须在你的实现中处理查询参数,如下所示:
get (smartapp / getDataViewModelConfig,application / json,(request,response) - > {
String id = request.queryParams(collId);
returnHI+ id;
}
I'm new to sparkjava. I want to read my request params using spark java but I'm not able to find the correct syntax. please help me out. Below is my route method and the client call to it:
my client request url:/smartapp/getDataViewModelConfig?collId=123'
Route Method:
get("smartapp/getDataViewModelConfig/:id", "application/json", (request, response)
-> {
String id = request.params(":id");
}
The 'id' field is returning null here. Any suggestions as to what went wrong here?
If you have to work with an URL like /smartapp/getDataViewModelConfig?collId=123
you have to deal with query parameters in your implementation, like the following:
get("smartapp/getDataViewModelConfig", "application/json", (request, response)->{
String id = request.queryParams("collId");
return "HI " + id;
}
这篇关于如何使用Spark Java框架获取请求参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!