在GET,JAVA中传递地图

时间:2018-07-10 01:30:08

标签: rest http-request-parameters

如何将键值对映射传递给GET REST API

这里是对资源的调用..我收到了不允许的方法

String queryMap= String.format("{'softwareversion':'%s','peril':'%s','analysistype':'%s', 'region':'%s'}", "HD18", "Flood", "EP", "USFL");
        String url = String.format("http://localhost:%d/templates/modelprofile?queryMap=%s", API_APPLICATION_RULE.getLocalPort(),queryMap);

    Response response = ClientBuilder.newClient()
            .target(url)
            .request()
            .header("Authorization", getToken())
            .get();

我的资源如下

@GET
    @Path("/{templateType}")
    @Timed
    @Produces(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "Get templates based on peril/region,version and type",
            httpMethod = ApiConstants.GET)
    @ApiResponses(value = {
            @ApiResponse(code = ApiConstants.INT_200,
                    message = "TemplateReader was retrieved successfully from the database."),
            @ApiResponse(code = ApiConstants.INT_400,
                    message = "Bad request (wrong or missing inputs)"),
            @ApiResponse(code = ApiConstants.INT_500,
                    message = ApiConstants.INTERNAL_SERVER_ERROR)
    })
public Template getTemplate(@ApiParam(hidden = true) @Auth User user,
                                  @ApiParam(name = "templateType", value = "templateType")
                                  @PathParam("templateType") String templateType,
                                  @ApiParam(name = "queryMap", value = "queryMap")
                                    @RequestParameters Map<String,String> queryMap
                                  ) throws ApiException

1 个答案:

答案 0 :(得分:0)

您可以使用以下请求参数传递它。

@RequestMapping(name = "/url/", method = RequestMethod.GET)
public void method_name(@RequestParam(name = "map_name")Map<String, Object> requestMap){
  //Process map and perform your logic
}