Rest 在GET中传递映射,JAVA
如何将键值对的映射传递给GET REST API 这是对资源的调用。。我得到了一个不允许的方法Rest 在GET中传递映射,JAVA,rest,http-request-parameters,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/templat
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
@GET
@路径(“/{templateType}”)
@定时
@产生(MediaType.APPLICATION_JSON)
@ApiOperation(value=“根据危险/地区、版本和类型获取模板”,
httpMethod=ApiConstants.GET)
@ApiResponses(值={
@ApiResponse(代码=ApiConstants.INT_200,
message=“TemplateReader已从数据库中成功检索。”),
@ApiResponse(代码=ApiConstants.INT_400,
message=“错误的请求(错误或缺少输入)”,
@ApiResponse(代码=ApiConstants.INT_500,
message=ApiConstants.INTERNAL\u SERVER\u错误)
})
公共模板getTemplate(@ApiParam(hidden=true)@Auth User,
@ApiParam(name=“templateType”,value=“templateType”)
@PathParam(“templateType”)字符串templateType,
@ApiParam(name=“queryMap”,value=“queryMap”)
@RequestParameters映射查询映射
)抛出异常
您可以使用如下请求参数传递它
@RequestMapping(name = "/url/", method = RequestMethod.GET)
public void method_name(@RequestParam(name = "map_name")Map<String, Object> requestMap){
//Process map and perform your logic
}
@RequestMapping(name=“/url/”,method=RequestMethod.GET)
public void方法\u name(@RequestParam(name=“map\u name”)map requestMap){
//流程映射并执行您的逻辑
}
你没有。您以类似JSON的数据格式发送数据。它将在服务器上反序列化为映射或POJO。顺便说一句,你在使用什么框架?你能看看上面的调用吗。。?