我在Spring rest服务中有一个方法。
@RequestMapping(value = "test/process", method = RequestMethod.POST)
public @ResponseBody MyResponse processRequest(String RequestId, int count)
我正在使用Spring RestTemplate来调用这个服务,如下:
RestTemplate restTemplate = this.getRestTemplate();
MultiValueMap<String, Object> map = new LinkedMultiValueMap<String, Object>();
map.add("RequestId", RequestId);
map.add("count", count);
restTemplate.postForObject(url, map,MyResponse.class);
当我尝试调用客户端方法时,出现了异常,提示找不到适合的HttpMessageConverter来处理请求类型[java.lang.Integer]
org.springframework.http.converter.HttpMessageNotWritableException: Could not write request: no suitable HttpMessageConverter found for request type [java.lang.Integer]
at org.springframework.http.converter.FormHttpMessageConverter.writePart(FormHttpMessageConverter.java:310)
at org.springframework.http.converter.FormHttpMessageConverter.writeParts(FormHttpMessageConverter.java:270)
at org.springframework.http.converter.FormHttpMessageConverter.writeMultipart(FormHttpMessageConverter.java:260)
at org.springframework.http.converter.FormHttpMessageConverter.write(FormHttpMessageConverter.java:200)
at org.springframework.http.converter.FormHttpMessageConverter.write(FormHttpMessageConverter.java:1)
at org.springframework.web.client.RestTemplate$HttpEntityRequestCallback.doWithRequest(RestTemplate.java:596)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:444)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:409)
at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:287)
我知道一种方法是将所有参数都传递为字符串。但是以后我可能需要将复杂的数据类型作为参数传递。 有什么办法可以实现这一点。 我已经搜索过了,一些选项似乎是编写自己的转换器。我该如何开始解决这个问题。
map.add("RequestId", RequestId);
RequestId是一个比字符串更复杂的对象吗?我们可以看到URL吗?谢谢! - java1337