我在Spring MVC控制器中有一个简单的REST方法,如下所示:
@RequestMapping(value =“/ person / ”,method = RequestMethod.GET)public @ResponseBody Object getPerson(@PathVariable(“personId”)String personId)
输出的类型为 Object
,因为此方法返回了几种不同的数据类型 .
从Spring MVC应用程序中的测试程序调用时,如下所示:
private static void getPerson() {
logger.info(Rest.class.getName() + ".getPerson() method called.");
RestTemplate restTemplate = new RestTemplate();
Person person = restTemplate.getForObject("http://localhost:8080/Library/rest/person/1", Person.class);
ObjectMapper responseMapper = new ObjectMapper();
...
}
响应是 Content type 'null' not supported
,呼叫失败 .
任何人都可以建议为什么?
当从另一个不使用Spring但发出HTTP GET请求的应用程序中的测试程序调用时,控制器方法被正确调用并起作用 .
1 回答
你可以试试这个:
如果以上不起作用,您可以尝试使用
Entity
方法,如:有很多useful examples here .
希望能有所帮助