Ajax 在SpringMVC2.5中使用jackson
很抱歉,我不能用谷歌搜索这个问题,我们在项目中使用SpringMVC2.5,所以没有@ResponseBody注释,没有它我怎么能做出类似的东西呢 您可以将其作为使用Jackson对象映射器生成的字符串返回:Ajax 在SpringMVC2.5中使用jackson,ajax,json,spring-mvc,jackson,Ajax,Json,Spring Mvc,Jackson,很抱歉,我不能用谷歌搜索这个问题,我们在项目中使用SpringMVC2.5,所以没有@ResponseBody注释,没有它我怎么能做出类似的东西呢 您可以将其作为使用Jackson对象映射器生成的字符串返回: public String getCustomDetails(@PathVariable String variable1) { CustomDetails details = new CustomDetails(variable1); ObjectMapper mapp
public String getCustomDetails(@PathVariable String variable1) {
CustomDetails details = new CustomDetails(variable1);
ObjectMapper mapper = new ObjectMapper();
String result = null;
result = mapper.writeValueAsString(details);
return result;
}
这应该行得通。可能必须在try-catch中围绕对writeValueAsString的调用
编辑:我应该澄清“CustomDetails”和“variable1”只是示例值。。。它们可以是任何东西。谢谢,我试试看。如果我需要返回复杂的对象,例如地图列表,该怎么办?或者以这种方式,它会起作用吗?我的直接想法是,是的,它会起作用。但我还没有试过,所以我不能确定它是否确实试过。祝你好运