我在Spring休息服务中有一个方法.
@RequestMapping(value = "test/process", method = RequestMethod.POST) public @ResponseBody MyResponse processRequest(String RequestId, int count)
我正在使用Spring RestTemplate来调用此服务.
RestTemplate restTemplate = this.getRestTemplate(); MultiValueMapmap = new LinkedMultiValueMap (); 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)
我知道其中一种方法是将所有参数作为String传递.但我可能需要稍后将复杂数据类型作为参数传递.有什么方法可以实现这一目标.我用谷歌搜索,一些选项似乎是编写我自己的转换器.我应该如何开始解决这个问题.