0

抱歉,一般问题,但我不能谷歌任何东西,我们在我们的项目中使用spring mvc 2.5,所以没有@ResponseBody 注释,没有它我怎么能做这样的事情

4

1 回答 1

1

您可以将其作为使用 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”只是示例值......它们可以是任何东西。

于 2013-07-29T14:40:37.087 回答