How to get the request parameters using get in Spark Java framework?

后端 未结 2 894
暗喜
暗喜 2021-02-12 11:04

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 clien

相关标签:
2条回答
  • 2021-02-12 11:24

    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;
    }
    
    0 讨论(0)
  • 2021-02-12 11:24

    If you have an URL like : http://localhost:4567/smartapp/getDataViewModelConfig/456 use the following code :

    get("/smartapp/getDataViewModelConfig/:id","application/json", ((request, response) -> {
                    response.type("application/json")
                    return  request.params(":id");
                }), gson::toJson);
    
    0 讨论(0)
提交回复
热议问题