Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ajax 在SpringMVC2.5中使用jackson_Ajax_Json_Spring Mvc_Jackson - Fatal编程技术网

Ajax 在SpringMVC2.5中使用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

很抱歉,我不能用谷歌搜索这个问题,我们在项目中使用SpringMVC2.5,所以没有@ResponseBody注释,没有它我怎么能做出类似的东西呢

您可以将其作为使用Jackson对象映射器生成的字符串返回:

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”只是示例值。。。它们可以是任何东西。

谢谢,我试试看。如果我需要返回复杂的对象,例如地图列表,该怎么办?或者以这种方式,它会起作用吗?我的直接想法是,是的,它会起作用。但我还没有试过,所以我不能确定它是否确实试过。祝你好运